Knowledge baseExam Center
ENEnglish
Choose language13

CKTIS / C#

String.Join — joining elements with a separator

String.Join combines elements into one string, inserting a separator between them. Null values are not skipped.

Version: .NET 10; repository net10.0 and LangVersion=preview; feature versions require per-entry verification

Syntax

string.Join(separator, values)
string.Join(separator, value, startIndex, count)

String.Join is a static System.String method; string.Join names the same method. It returns combined text, placing the separator only between elements.

In .NET 10, overloads support string or char separators, arrays, IEnumerable<T>, and ReadOnlySpan spans. Object overloads use ToString(). The startIndex and count overload selects an array segment.

Empty input produces String.Empty. A null separator means empty text; a null element does too, but retains its position. A null array or collection causes ArgumentNullException; an invalid range causes ArgumentOutOfRangeException.

Examples

using System;

string?[] values = { "red", null, "blue" };
Console.WriteLine(string.Join("|", values));
Console.WriteLine(string.Join("|", values, 1, 2));
Console.WriteLine($"[{string.Join("|", Array.Empty<string>())}]");

Result

red||blue
|blue
[]

The displayed code and declared result were verified in an isolated environment using the method recorded in the verification evidence for this exact version.

Sources