Information
The topic you requested is included in another documentation set. For convenience, it's displayed below. Choose Switch to see the topic in its original location.

String.Join Method (String, String[])

Updated: January 2011

Concatenates a specified separator String between each element of a specified String array, yielding a single concatenated string.

Namespace:  System
Assembly:  mscorlib (in mscorlib.dll)

public static string Join(
	string separator,
	params string[] value
)

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.String
A string that consists of the elements in value delimited by the separator string. If value is an empty array, the method returns String.Empty.

ExceptionCondition
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);
   }
}


Silverlight

Supported in: 5, 4, 3

Silverlight for Windows Phone

Supported in: Windows Phone OS 7.1, Windows Phone OS 7.0

XNA Framework

Supported in: Xbox 360, Windows Phone OS 7.0

For a list of the operating systems and browsers that are supported by Silverlight, see Supported Operating Systems and Browsers.

Date

History

Reason

January 2011

Noted that an empty string is substituted for any null element in the array.

Customer feedback.

Was this page helpful?
(1500 characters remaining)
Thank you for your feedback

Community Additions

Show:
© 2014 Microsoft