String.Join Method (String, String[])
[ This article is for Windows Phone 8 developers. If you’re developing for Windows 10, see the latest documentation. ]
Concatenates a specified separator String between each element of a specified String array, yielding a single concatenated string.
Assembly: mscorlib (in mscorlib.dll)
Parameters
- separator
- Type: System.String
The string to use as a separator.
- value
- Type:
System.String
[]
An array that contains the elements to concatenate.
Return Value
Type: System.StringA string that consists of the elements in value delimited by the separator string. If value is an empty array, the method returns String.Empty.
| Exception | Condition |
|---|---|
| ArgumentNullException | value is null. |
For example if separator is ", " and the elements of value are "apple", "orange", "grape", and "pear", Join(separator, value) returns "apple, orange, grape, pear".
If separator is null, an empty string (Empty) is used instead. If any element in value is null, an empty string is used instead.
The following example demonstrates the Join method.
using System; public class Example { public static void Demo(System.Windows.Controls.TextBlock outputBlock) { outputBlock.Text += String.Format(MakeLine(0, 5, ", ")) + "\n"; outputBlock.Text += String.Format(MakeLine(1, 6, " ")) + "\n"; outputBlock.Text += String.Format(MakeLine(9, 9, ": ")) + "\n"; outputBlock.Text += String.Format(MakeLine(4, 7, "< ")) + "\n"; } private static string MakeLine(int initVal, int multVal, string sep) { string[] sArr = new string[10]; for (int i = initVal; i < initVal + 10; i++) sArr[i - initVal] = String.Format("{0,-3}", i * multVal); return String.Join(sep, sArr); } }