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
What are cshtml files?
Why static variables are used?
What is private readonly in c#?
What is Co- and Contra-Variance in C#?
what is IDisposal interface
What is regex c#?
What is an array? Give the syntax for a single and multi-dimensional array?
What is for loop in c#?
What is the difference between finalize() and dispose() methods?
What is master page in asp net c#?
What is class method?
What is public, private, protected, internal and internal protected?
What is assembly version series sequence?
Can an int be negative c#?
How does c# achieve polymorphism?