C# join string
last modified October 16, 2026
In this article we show 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. The
separator is not added before the first or after the last 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>)
These are the main overloads of the string.Join method. The
separator can be a char or a string. Since .NET 9,
there are also overloads that take a ReadOnlySpan of strings or
objects; the compiler uses them when we pass the values directly as arguments,
such as string.Join(", ", a, b, c).
C# join string - list of strings
The following example joins a list of strings.
List<string> words = ["falcon", "wood", "cloud", "cup", "sky", "water"];
var text = string.Join(',', words);
Console.WriteLine(text);
We have a list of words. We join all the words of the list with a comma.
$ dotnet run falcon,wood,cloud,cup,sky,water
C# join string - specify elements to join
We can specify which elements to join.
string[] words = ["falcon", "wood", "cloud", "cup", "sky", "water"];
var text = string.Join(',', words, 0, 3);
Console.WriteLine(text);
var text2 = string.Join(", ", words[^3..]);
Console.WriteLine(text2);
In the example, we join the first three elements and the last three elements of the array.
var text = string.Join(',', words, 0, 3);
The third argument is the starting index, the fourth is the number of elements to join. This overload exists only for string arrays.
var text2 = string.Join(", ", words[^3..]);
Alternatively, we can select the elements with a range.
$ dotnet run falcon,wood,cloud cup, sky, water
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);
Console.WriteLine(text);
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. Each object is
converted to a string with its ToString method.
$ dotnet run 1-2.3-False-falcon
C# join string - culture
Numbers and dates are converted to strings using the current culture. In some cultures, the decimal separator is a comma.
using System.Globalization;
double[] vals = [1.5, 2.25, 3.0];
Console.WriteLine(string.Join("; ", vals));
CultureInfo.CurrentCulture = CultureInfo.GetCultureInfo("sk-SK");
Console.WriteLine(string.Join("; ", vals));
Console.WriteLine(string.Join("; ", vals.Select(v => v.ToString(CultureInfo.InvariantCulture))));
We join the same values with the English and the Slovak culture. To get the same result regardless of the culture, we convert the values with the invariant culture first.
$ dotnet run 1.5; 2.25; 3 1,5; 2,25; 3 1.5; 2.25; 3
C# join string - LINQ and IEnumerable
In the following example, we use LINQ and the overload of the
Join method which takes an IEnumerable.
List<string> words = ["sky", "cup", "ocean", "dry", "tool", "rust"];
var text = string.Join(",", words.Where(e => e.Length == 3));
Console.WriteLine(text);
We have a list of words. We join all words from the list that have three letters.
$ dotnet run sky,cup,dry
C# join string - null and empty elements
Null elements are treated as empty strings. The separator is still added around them.
string?[] vals = ["sky", null, "cup", "", "ocean"];
Console.WriteLine(string.Join(",", vals));
Console.WriteLine(string.Join(",", vals.Where(v => !string.IsNullOrEmpty(v))));
To skip null and empty elements, we filter them out first.
$ dotnet run sky,,cup,,ocean sky,cup,ocean
C# join string - records
In the following example we join records.
List<User> users =
[
new("John Doe", "gardener"),
new("Roger Roe", "driver"),
new("Lucia Smith", "teacher")
];
var text = string.Join(Environment.NewLine, users);
Console.WriteLine(text);
record User(string Name, string Occupation);
We have a list of users. We join them with the newline string of the current
platform. Records provide a readable ToString implementation.
$ dotnet run
User { Name = John Doe, Occupation = gardener }
User { Name = Roger Roe, Occupation = driver }
User { Name = Lucia Smith, Occupation = teacher }
C# join string - create ASCII alphabet
In the next example, we create the ASCII alphabet.
var lower = string.Join(" ", Enumerable.Range('a', 26).Select(c => (char) c));
var upper = string.Join(" ", Enumerable.Range('A', 26).Select(c => (char) c));
Console.WriteLine(lower);
Console.WriteLine(upper);
In the ASCII table, there are 26 lowercase and 26 uppercase letters. Their
codes start at 97 and 65, respectively. The Enumerable.Range
method generates the codes, which we convert back to characters.
$ 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
C# string.Concat and StringBuilder.AppendJoin
The string.Concat method joins values without a separator. The
StringBuilder.AppendJoin method appends joined values to a string
builder; it is useful when we build a larger text.
using System.Text;
int[] nums = [1, 2, 3, 4, 5];
Console.WriteLine(string.Concat("sky", "cup", "ocean"));
Console.WriteLine(string.Concat(nums));
var sb = new StringBuilder("Numbers: ");
sb.AppendJoin(", ", nums);
sb.Append('.');
Console.WriteLine(sb);
We concatenate three strings and five numbers, and build a sentence with a string builder.
$ dotnet run skycupocean 12345 Numbers: 1, 2, 3, 4, 5.
Source
In this article we have joined strings in C#.
Author
List all C# tutorials.