C# join string

last modified July 5, 2023

C# join string tutorial shows how to join strings in C# with string.Join.

C# string.Join

The string.Join method concatenates the elements of a specified array or collection using the provided separator between each element.

Join(Char, Object[])
Join(Char, String[])
Join(String, IEnumerable<String>)
Join(String, Object[])
Join(String, String[])
Join(Char, String[], Int32, Int32)
Join(String, String[], Int32, Int32)
Join<T>(Char, IEnumerable<T>)
Join<T>(String, IEnumerable<T>)

There are nine overloaded string.Join methods.

C# join string - list of strings

The following example joins a list of strings.

var words = new List<string> {"falcon", "wood", "cloud", "cup", "sky", "water"};

var text = string.Join(',', words);

We have a list of words. We join all the words of the list with comma.

$ dotnet run

C# join string - specify elements to join

We can specify which elements to join.

var words = new string[] {"falcon", "wood", "cloud", "cup", "sky", "water"};

var text = string.Join(',', words, 0, 3);

In the example, we join the first three elements of the array.

var text = string.Join(',', words, 0, 3);

The third element is the starting index, the fourth is the number of elements to join.

$ dotnet run

C# join string - array of objects

We can join various types of objects in an array.

object[] vals = { 1, 2.3, false, "falcon" };

var text = string.Join("-", vals);

We have an array of objects: an integer, a floating point value, a boolean, and a string. We join all these objects with a dash character.

$ dotnet run

C# join string - LINQ and IEnumerable

In the following example, we use LINQ and the overloaded Join method, which uses IEnumerable.

var words = new List<string> {"sky", "cup", "ocean", "dry", "tool", "rust"};

var text = string.Join(",", words.Where(e => e.Length == 3));

We have a list of words. We join all words from the list that have three letters.

$ dotnet run

C# join string - records

In the following example we join records.

var users = new List<User> { new ("John Doe", "garderner"), 
    new ("Roger Roe", "driver"), new ("Lucia Smith", "teacher")};

var text = string.Join("\n", users);

record User(string name, string occupation);

We have a list of users. We join them with a newline character.

$ dotnet run
User { name = John Doe, occupation = garderner }
User { name = Roger Roe, occupation = driver }
User { name = Lucia Smith, occupation = teacher }

C# join string - create ASCII alphabet

In the next example, we create an ASCII alphabet.

int idx1 = 97;
int idx2 = 65;

var text = string.Join(" ", CreateAlphabet());

List<char> CreateAlphabet() {

    var vals = new List<char>();

    int span1 = idx1 + 25;
    for (int i = idx1; i <= span1; i++) 

    int span2 = idx2 + 25;
    for (int i = idx2; i <= span2; i++) 

    return vals;

In the ASCII table, there are 25 lower-case letters and 25 upper-case letters. Their indexes start from 97 and 65, respectively.

$ dotnet run
a b c d e f g h i j k l m n o p q r s t u v w x y z A B C D E F G H I J K L M N O P Q R S T U V W X Y Z


string.Join method

In this article we have joined strings in C# language.


My name is Jan Bodnar and I am a passionate programmer with many years of programming experience. I have been writing programming articles since 2007. So far, I have written over 1400 articles and 8 e-books. I have over eight years of experience in teaching programming.

List all C# tutorials.