how to convert String array to StringBuilder array or vice
versa?

Answer Posted / krishana singh gniit

using System;
using System.Text;

class Program
{
static void Main()
{
//
// Create an array with five strings.
//
string[] array = new string[5];
array[0] = "Dot";
array[1] = "Net";
array[2] = "Perls";
array[3] = "Sam";
array[4] = "Allen";

//
// Call the methods.
//
string result1 = ConvertStringArrayToString(array);
string result2 = ConvertStringArrayToStringJoin
(array);

//
// Display the results.
//
Console.WriteLine(result1);
Console.WriteLine(result2);
Console.Read();
}

static string ConvertStringArrayToString(string[] array)
{
//
// Concatenate all the elements into a
StringBuilder.
//
StringBuilder builder = new StringBuilder();
foreach (string value in array)
{
builder.Append(value);
builder.Append('.');
}
return builder.ToString();
}

static string ConvertStringArrayToStringJoin(string[]
array)
{
//
// Use string Join to concatenate the string
elements.
//
string result = string.Join(".", array);
return result;
}
}

Is This Answer Correct ?    3 Yes 2 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What are cshtml files?

488


Why static variables are used?

522


What is private readonly in c#?

521


What is Co- and Contra-Variance in C#?

540


what is IDisposal interface

677






What is regex c#?

494


What is an array? Give the syntax for a single and multi-dimensional array?

491


What is for loop in c#?

505


What is the difference between finalize() and dispose() methods?

531


What is master page in asp net c#?

474


What is class method?

473


What is public, private, protected, internal and internal protected?

531


What is assembly version series sequence?

538


Can an int be negative c#?

585


How does c# achieve polymorphism?

473