C# String Join() Method

Beginner
5 min read
Updated: Nov 2026
3 examples
String

Definition

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)
CallWhat 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

ParameterDescription
separatorRequired. The text (or char) placed between items. It can be "".
value / valuesRequired. The items to join: an array, a list, or individual arguments.
startIndex, countOptional (array overload). Join only count items starting at startIndex.

Return Value

Return ValueDescription
stringOne 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);
    }
}

How It Works

  1. Between, not around. Three items need two separators, so there is no trailing comma.
  2. A multi-character separator. ", " is two characters: a comma and a space.
  3. Loose arguments. Thanks to params, you can pass values one by one instead of building an array first.
  4. 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");
    }
}

How It Works

  1. Any collection. A List<string> works just like an array, because Join accepts IEnumerable<string>.
  2. Two items, one separator. The list has two names, so " & " appears once.
  3. Numbers become text. For a List<int>, the generic overload calls ToString() on each number.
  4. 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.

C#
using System;

class Program {
    static void Main() {
        string?[] parts = { "a", null, "c" };
        Console.WriteLine(string.Join('|', parts));

        string[] path = { "home", "sam", "docs", "file.txt" };
        Console.WriteLine(string.Join("/", path, 0, 3));

        string[] none = { };
        Console.WriteLine("[" + string.Join(",", none) + "]");
    }
}

How It Works

  1. null counts as empty. The missing middle item becomes nothing, but its separators remain, so you see two bars in a row.
  2. A char separator. '|' uses the char overload from newer .NET. Use "|" on .NET Framework.
  3. Only the first three. The 0, 3 arguments mean “start at index 0 and take 3 items”, so file.txt is left out.
  4. Nothing to join. An empty array gives an empty string, shown as []. No exception is thrown.

Frequently Asked Questions

It combines the items of an array, list, or argument list into one string, placing a separator between each pair of items.
Call string.Join(", ", list). It works with arrays, List<string>, and any IEnumerable<string>.
Yes. string.Join(",", new[] { 1, 2, 3 }) gives "1,2,3". The generic overload calls ToString() on each item.
They are treated as empty strings. The separators around them are still added.
Join puts a separator between items. Concat simply glues them together with nothing in between.

Next: LastIndexOf()

Find the last position of a character or substring by searching from the end.

LastIndexOf() tutorial →

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

15 people found this page helpful