In C#, string.Join() takes many values and glues them into one string, putting a separator between each pair. string.Join(", ", names) turns an array of names into "Ana, Ben, Cy". The separator is added between items only, never at the start or the end.
It works with arrays, lists, and any IEnumerable, including numbers (they are turned into text with ToString()). It is the opposite of Split(). Because it is static, you call it on string, not on the separator or the list.
This is a static member of System.String. Call it on the type, such as string.Join(...), not on a string variable. Like every string method, it never changes its inputs: it returns one new string and the array or list you passed stays exactly as it was.
Syntax
Pass the separator first, then the values.
C#
string[] words = { "red", "green", "blue" };
string a = string.Join(", ", words); // "red, green, blue"
string b = string.Join("-", "2026", "11", "18"); // "2026-11-18"
string c = string.Join('|', words); // "red|green|blue" (newer .NET)
Call
What it does
string.Join(", ", array)
Join every item of a string array.
string.Join(" ", list)
Join a List<string> or any IEnumerable<string>.
string.Join("+", numbers)
Join numbers; each is converted with ToString().
string.Join("/", array, 0, 3)
Join only 3 items, starting at index 0.
string.Join(',', array)
Use a char separator (newer .NET, .NET Core 2.0 and later).
A null item is treated as an empty string, so { "a", null, "c" } joined with | gives "a||c". An empty collection gives "". A null separator is treated as "". A null array or list throws ArgumentNullException.
Library declarations
C#
public static string Join(string? separator, params string?[] value);
public static string Join(string? separator, params object?[] values);
public static string Join(string? separator, IEnumerable<string?> values);
public static string Join<T>(string? separator, IEnumerable<T> values);
public static string Join(string? separator, string?[] value, int startIndex, int count);
public static string Join(char separator, params string?[] value); // newer .NET
public static string Join(char separator, params object?[] values); // newer .NET
Parameters
Parameter
Description
separator
Required. The text (or char) placed between items. It can be "".
value / values
Required. The items to join: an array, a list, or individual arguments.
startIndex, count
Optional (array overload). Join only count items starting at startIndex.
Return Value
Return Value
Description
string
One new string with all items and separators. "" when there are no items.
C# Examples
Example 1 — Join an Array and Separate Values
Join a string array with a comma and a space, and join three separate values with a dash.
C#
using System;
class Program {
static void Main() {
string[] words = { "red", "green", "blue" };
Console.WriteLine(string.Join(", ", words));
Console.WriteLine(string.Join("-", "2026", "11", "18"));
Console.WriteLine(words.Length);
}
}
Output
red, green, blue
2026-11-18
3
How It Works
Between, not around. Three items need two separators, so there is no trailing comma.
A multi-character separator.", " is two characters: a comma and a space.
Loose arguments. Thanks to params, you can pass values one by one instead of building an array first.
The array is untouched.words still holds three separate strings; Join made a new, combined one.
Example 2 — Join a List of Names and a List of Numbers
Join accepts lists, and it converts numbers to text for you.
C#
using System;
using System.Collections.Generic;
class Program {
static void Main() {
List<string> names = new List<string> { "Ana", "Ben" };
Console.WriteLine(string.Join(" & ", names));
List<int> nums = new List<int> { 1, 2, 3 };
Console.WriteLine(string.Join("+", nums) + " = 6");
}
}
Output
Ana & Ben
1+2+3 = 6
How It Works
Any collection. A List<string> works just like an array, because Join accepts IEnumerable<string>.
Two items, one separator. The list has two names, so " & " appears once.
Numbers become text. For a List<int>, the generic overload calls ToString() on each number.
Keep building. The joined result is a normal string, so adding " = 6" afterwards works as usual.
Example 3 — Null Items, a Range of Items, and an Empty Array
See how Join treats null entries, join only part of an array, and join nothing at all.