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 is enum in c#?
What do you mean by a windows process in regards to memory allocation?
What are the 3 different types of arrays?
How do you declare a method in c#?
What is difference between an reference type and value type in C#?
What is datetime minvalue in c#?
what is method overloading in c#?
How can we set the class to be inherited, but prevent the method from being over-ridden?
What is primitive types in c#?
Explain the use of Mutex in C#?
Why it's said that writing into .NET Application Configuration Files is a Bad Idea?
Is Facebook a desktop application?
What are examples of desktop applications?
Why do we use hashtable in c#?
Is cli same as the clr?