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 application object in c#?
What is c# best for?
What does the keyword “virtual†declare for a method or property?
What is the syntax for calling an overloaded constructor within a constructor?
Is string passed by reference in c#?
Can namespace contain the private class?
How do you prevent a class from being inherited in c#?
How to get the sum of last 3 items in a list using lambda expressions?
What is dataset and dataadapter in c#?
Is c++ or c# better?
Where do we set the min and max pool size for connection pooling?
Explain the concepts of cts and cls(common language specification).
If you want to convert a base type to a derived type, what type of conversion do you use?
How long will it take to learn c#?
Is Multiple-inheritance supported by c#?