C# Language Concat string array elements using String.Join


Example

The String.Join method can be used to concatenate multiple elements from a string array.

string[] value = {"apple", "orange", "grape", "pear"};
string separator = ", ";

string result = String.Join(separator, value, 1, 2);
Console.WriteLine(result);

Produces the following output: "orange, grape"

This example uses the String.Join(String, String[], Int32, Int32) overload, which specifies the start index and count on top of the separator and value.

If you do not wish to use the startIndex and count overloads, you can join all string given. Like this:

string[] value = {"apple", "orange", "grape", "pear"};
string separator = ", ";
string result = String.Join(separator, value);
Console.WriteLine(result);

which will produce;

apple, orange, grape, pear