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
Is concurrent queue thread safe?
To whom a method is accesssed if it is marked as protected internal ?
windows c# using datagridview in edit form sql server
What is difference between array and list in c#?
What are strongly typed objects?
What is the difference between xml documentation tag?
How are delegates chosen?
What is deferred execution?
Can interface have virtual methods in c#?
How you will create satellite assemblies?
What are scriptable objects?
Can you have more than one namespace in c#?
When a Static Constructor is called in a Class?
What is thread in c#?
What is garbage collector and where should you use in .NET?