C# List to String
last modified November 15, 2026
This article shows how to convert a list to a string in C#.
The usual tool is the string.Join method, which puts a
separator between the elements of a collection. Other options are
string.Concat, the StringBuilder class, the LINQ
Aggregate method, and plain concatenation with the
+ operator. They differ in convenience and, for large lists, a
lot in speed.
List ToString
A list does not override the ToString method, so it cannot be
printed directly.
List<string> words = ["a", "visit", "to", "London"];
Console.WriteLine(words);
Console.WriteLine(words.ToString());
Console.WriteLine($"{words}");
We try to print a list in three ways.
Console.WriteLine(words);
Console.WriteLine, string interpolation, and an explicit
ToString call all end in Object.ToString, which
returns the name of the type. The `1 suffix means a generic type
with one type parameter. To see the elements, we must build the string
ourselves.
$ dotnet run System.Collections.Generic.List`1[System.String] System.Collections.Generic.List`1[System.String] System.Collections.Generic.List`1[System.String]
Using string.Join
string.Join concatenates the elements of a collection and
inserts a separator between them. The separator can be a string or a
character.
List<string> words = ["a", "visit", "to", "London"];
Console.WriteLine(string.Join("-", words));
Console.WriteLine(string.Join(", ", words));
Console.WriteLine(string.Join('|', words));
List<string> one = ["alone"];
List<string> none = [];
Console.WriteLine($"[{string.Join(", ", one)}]");
Console.WriteLine($"[{string.Join(", ", none)}]");
We join a list of words with different separators.
Console.WriteLine(string.Join("-", words));
Joining with hyphens creates a slug from the words.
Console.WriteLine($"[{string.Join(", ", one)}]");
Console.WriteLine($"[{string.Join(", ", none)}]");
The separator goes only between the elements, never after the last one. A
list with one element gives that element and an empty list gives an empty
string. string.Join computes the final length first and
allocates the result once, so it is efficient for large lists too.
$ dotnet run a-visit-to-London a, visit, to, London a|visit|to|London [alone] []
Joining non-string elements
string.Join has an overload that takes an
IEnumerable<T>; it calls ToString on each
element.
List<int> nums = [1, 2, 3, 4, 5];
Console.WriteLine(string.Join(" + ", nums) + $" = {nums.Sum()}");
List<decimal> prices = [12.5m, 7m, 99.99m];
Console.WriteLine(string.Join("; ", prices.Select(p => p.ToString("F2"))));
List<User> users = [new("John", 34), new("Lucy", 28)];
Console.WriteLine(string.Join(Environment.NewLine, users));
List<string?> items = ["sky", null, "owl"];
Console.WriteLine(string.Join(", ", items));
record User(string Name, int Age);
We join lists of integers, decimals, records, and nullable strings.
Console.WriteLine(string.Join(" + ", nums) + $" = {nums.Sum()}");
The integers are converted to strings automatically.
Console.WriteLine(string.Join("; ", prices.Select(p => p.ToString("F2"))));
To control the format, we convert the elements with Select
first. The F2 format always gives two decimal places. Without an
explicit culture, the current culture decides the decimal separator.
Console.WriteLine(string.Join(Environment.NewLine, users));
A record has a compiler-generated
ToString that prints its properties. With
Environment.NewLine as the separator, each user is on its own
line.
Console.WriteLine(string.Join(", ", items));
A null element becomes an empty string; no exception is
thrown.
$ dotnet run
1 + 2 + 3 + 4 + 5 = 15
12.50; 7.00; 99.99
User { Name = John, Age = 34 }
User { Name = Lucy, Age = 28 }
sky, , owl
Formatting the elements
Combined with LINQ, string.Join can quote, number, or filter the
elements before joining them.
List<string> words = ["sky", "blue", "cloud", "rain"];
Console.WriteLine(string.Join(", ", words.Select(w => $"'{w}'")));
Console.WriteLine(string.Join(", ", words.Select((w, i) => $"{i + 1}. {w}")));
Console.WriteLine(string.Join(", ", words.Where(w => w.Length > 3)
.Select(w => w.ToUpperInvariant())));
Console.WriteLine($"[{string.Join(", ", words.Select(w => $"\"{w}\""))}]");
We create four different strings from a list of words.
Console.WriteLine(string.Join(", ", words.Select((w, i) => $"{i + 1}. {w}")));
This overload of Select passes the index of each element to the
lambda, so we can number the words.
Console.WriteLine($"[{string.Join(", ", words.Select(w => $"\"{w}\""))}]");
Here we produce something that looks like a JSON array. For real JSON, use a
serializer such as System.Text.Json, which also escapes special
characters; see the JSON article.
$ dotnet run 'sky', 'blue', 'cloud', 'rain' 1. sky, 2. blue, 3. cloud, 4. rain BLUE, CLOUD, RAIN ["sky", "blue", "cloud", "rain"]
Using string.Concat
string.Concat joins the elements without a separator. Like
string.Join, it allocates the result only once.
List<string> words = ["There", "are", "three", "chairs", "and", "two",
"lamps", "in", "the", "room"];
Console.WriteLine(string.Concat(words));
Console.WriteLine(string.Concat(words.Select(w => w[0])));
List<char> chars = ['f', 'a', 'l', 'c', 'o', 'n'];
Console.WriteLine(string.Concat(chars));
Console.WriteLine(new string(chars.ToArray()));
We concatenate words and characters.
Console.WriteLine(string.Concat(words.Select(w => w[0])));
We take the first letter of each word. string.Concat accepts a
sequence of any type and calls ToString on the elements.
Console.WriteLine(string.Concat(chars)); Console.WriteLine(new string(chars.ToArray()));
A list of characters can be turned into a string with
string.Concat or with the string constructor, which
takes a character array.
$ dotnet run Therearethreechairsandtwolampsintheroom Tatcatlitr falcon falcon
Using StringBuilder
StringBuilder is a mutable buffer for building strings. It is
the right choice when the list is only a part of a larger text.
using System.Text;
List<string> words = ["There", "are", "three", "chairs", "and", "two",
"lamps", "in", "the", "room"];
var builder = new StringBuilder();
builder.Append("Words: ");
builder.AppendJoin(' ', words);
builder.Append('.');
Console.WriteLine(builder);
var sb = new StringBuilder();
foreach (var word in words)
{
if (sb.Length > 0)
{
sb.Append(' ');
}
sb.Append(word);
}
Console.WriteLine($"[{sb}]");
We build two strings from a list of words.
builder.Append("Words: ");
builder.AppendJoin(' ', words);
builder.Append('.');
AppendJoin is the StringBuilder version of
string.Join; it appends the elements with a separator.
foreach (var word in words)
{
if (sb.Length > 0)
{
sb.Append(' ');
}
sb.Append(word);
}
When we append the elements in a loop, a common mistake is to add a separator after each element, which leaves a trailing space. Adding the separator before every element except the first avoids it. The brackets in the output show that there is no extra space. More in the StringBuilder article.
$ dotnet run Words: There are three chairs and two lamps in the room. [There are three chairs and two lamps in the room]
Using Enumerable.Aggregate
The LINQ Aggregate method applies an accumulator function to the
elements of a sequence.
List<string> words = ["There", "are", "three", "chairs", "and", "two",
"lamps", "in", "the", "room"];
var res = words.Aggregate((total, part) => $"{total} {part}");
Console.WriteLine(res);
var res2 = words.Aggregate("Words:", (total, part) => $"{total} {part}");
Console.WriteLine(res2);
List<string> empty = [];
Console.WriteLine($"[{empty.Aggregate("", (t, p) => t + p)}]");
try
{
empty.Aggregate((t, p) => t + p);
}
catch (InvalidOperationException e)
{
Console.WriteLine(e.Message);
}
We build strings with two overloads of Aggregate.
var res = words.Aggregate((total, part) => $"{total} {part}");
Without a seed, the first element is the initial value of the accumulator and the function is called for the rest of the elements.
var res2 = words.Aggregate("Words:", (total, part) => $"{total} {part}");
The seed is the initial value; the function is called for every element.
empty.Aggregate((t, p) => t + p);
On an empty list, the overload without a seed throws an
InvalidOperationException; the seeded one returns the seed. Each
step creates a new string, so Aggregate gets slow for large
lists, as we will see below.
$ dotnet run There are three chairs and two lamps in the room Words: There are three chairs and two lamps in the room [] Sequence contains no elements
Using string concatenation
A list can also be converted with the += operator in a loop.
List<string> words = ["There", "are", "three", "chairs", "and", "two",
"lamps", "in", "the", "room"];
string res = string.Empty;
foreach (var word in words)
{
res += word + " ";
}
Console.WriteLine($"[{res}]");
Console.WriteLine($"[{res.TrimEnd()}]");
We append each word and a space to the result.
foreach (var word in words)
{
res += word + " ";
}
Strings are immutable, so every += creates a new string and
copies the old content into it. The result also has a trailing space, which
we remove with TrimEnd.
$ dotnet run [There are three chairs and two lamps in the room ] [There are three chairs and two lamps in the room]
Comparing the speed
For a few elements, all the approaches are fast enough. The difference shows with large lists.
using System.Diagnostics;
using System.Text;
List<string> words = Enumerable.Range(0, 50_000).Select(i => $"word{i}").ToList();
var sw = Stopwatch.StartNew();
string r1 = string.Empty;
foreach (var word in words)
{
r1 += word + " ";
}
Console.WriteLine($"{"+=",-14}{sw.ElapsedMilliseconds,5} ms");
sw.Restart();
string r2 = words.Aggregate((t, p) => t + " " + p);
Console.WriteLine($"{"Aggregate",-14}{sw.ElapsedMilliseconds,5} ms");
sw.Restart();
var sb = new StringBuilder();
sb.AppendJoin(' ', words);
string r3 = sb.ToString();
Console.WriteLine($"{"StringBuilder",-14}{sw.ElapsedMilliseconds,5} ms");
sw.Restart();
string r4 = string.Join(" ", words);
Console.WriteLine($"{"string.Join",-14}{sw.ElapsedMilliseconds,5} ms");
Console.WriteLine(r1.TrimEnd() == r2 && r2 == r3 && r3 == r4);
Console.WriteLine(r4.Length);
We join a list of 50,000 words with each method and measure the time with Stopwatch.
r1 += word + " ";
Concatenation in a loop and Aggregate copy the whole string
built so far in each step, so the total work grows with the square of the
number of elements. The result here is almost 490,000 characters long.
string r4 = string.Join(" ", words);
StringBuilder and string.Join copy each word only
once or twice and finish in about a millisecond. The last but one line
confirms that all four results are equal. The exact times depend on the
machine; for precise measurements, use a tool like
BenchmarkDotNet.
$ dotnet run += 6001 ms Aggregate 2498 ms StringBuilder 1 ms string.Join 0 ms True 488889
Source
StringBuilder.AppendJoin method - .NET API
In this article we have converted lists to strings in C#. Use
string.Join unless you have a reason not to. See also the
join string,
List, and
string tutorials.
Author
List all C# tutorials.