C# String Join(String, String[])

Description

String Join(String, String[]) concatenates all the elements of a string array, using the specified separator between each element.

Syntax

String.Join(String, String[]) has the following syntax.


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

Parameters

String.Join(String, String[]) has the following 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

String.Join(String, String[]) method 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.

Example

The following example demonstrates the Join method.


/*  w  ww  .jav  a 2s .  c om*/
using System;

public class JoinTest {
    public static void Main() {

        Console.WriteLine(String.Join("-", new String[]{"a","b"}));
    }
}

The code above generates the following result.





















Home »
  C# Tutorial »
    System »




Array
BitConverter
Boolean
Byte
Char
Console
ConsoleKeyInfo
Convert
DateTime
DateTimeOffset
Decimal
Double
Enum
Environment
Exception
Guid
Int16
Int32
Int64
Math
OperatingSystem
Random
SByte
Single
String
StringComparer
TimeSpan
TimeZone
TimeZoneInfo
Tuple
Tuple
Tuple
Type
UInt16
UInt32
UInt64
Uri
Version