System.String.Join Method

Concatenates all the elements of a string array, using the specified separator between each element.

Syntax

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

Parameters

separator
The string to use as a separator. separator is included in the returned string only if value has more than one element.
value
An array that contains the elements to concatenate.

Returns

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.

Exceptions

TypeReason
ArgumentNullException value is a null reference.

Remarks

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 (string.Empty) is used instead. If any element in value is null, an empty string is used instead.

Example

The following example demonstrates the string.Join(string, String[]) method.

C# Example

using System;
public class StringJoin {
 public static void Main() {
 String[] strAry = { "Red" , "Green" , "Blue" };
 Console.WriteLine( String.Join( " :: ", strAry ) );
 }
}

The output is

Red :: Green :: Blue

Requirements

Namespace: System
Assembly: mscorlib (in mscorlib.dll)
Assembly Versions: 1.0.5000.0, 2.0.0.0, 4.0.0.0