Moose Factory Moose Factory - 10 days ago 6
C# Question

Convert a string array to a concantenated string in C#

Is there an easy way to convert a string array into a concantenated string?

For example, I have a string array:

new string[]{"Apples", "Bananas", "Cherries"};


And I want to get a single string:

"Apples,Bananas,Cherries"


Or
"Apples&Bananas&Cherries"
or
"Apples\Bananas\Cherries"

Answer

A simple one...

string[] theArray = new string[]{"Apples", "Bananas", "Cherries"};
string s = string.Join(",",theArray);