ZetCode

C# List to String

Last modified April 18, 2025

This tutorial demonstrates how to convert a List to a string in C#.

To convert a list of elements into a single string in C#, we can use the string.Join method, StringBuilder class, Enumerable.Aggregate method, or the string concatenation operator.

The string.Join method combines elements of a collection or array, inserting a specified separator between each element. The StringBuilder class efficiently builds strings dynamically. The Enumerable.Aggregate method applies an accumulator function across a sequence of values.

C# uses the + operator to concatenate strings, though this can be less efficient for large lists.

Using string.Join

The following example uses the string.Join method to convert a list into a string.

Program.cs
List<string> words = ["a", "visit", "to", "London"];
var res = string.Join("-", words);

Console.WriteLine(res);

This example creates a slug from a list of words by joining them with hyphens.

$ dotnet run
a-visit-to-London

Using StringBuilder

This example demonstrates the use of the StringBuilder class to build a string from a list.

Program.cs
using System.Text;

List<string> words = ["There", "are", "three", "chairs", "and", "two",
    "lamps", "in",  "the", "room"];

var builder = new StringBuilder();

foreach (var word in words)
{
    builder.Append(word).Append(' ');
}

Console.WriteLine(builder.ToString());

The code iterates through the list using a foreach loop, appending each word and a space to a StringBuilder object. The ToString method converts the result to a string.

$ dotnet run
There are three chairs and two lamps in the room

Using Enumerable.Aggregate

The next example employs the Enumerable.Aggregate method to convert a list to a string.

Program.cs
List<string> words = ["There", "are", "three", "chairs", "and", "two", 
    "lamps", "in",  "the", "room"];

var res = words.Aggregate((total, part) => $"{total} {part}");
Console.WriteLine(res);

This example uses string interpolation within the accumulator function to build the string by concatenating each word with a space.

Using String Concatenation

This example uses the string concatenation operator to build a string from a list.

Program.cs
List<string> words = ["There", "are", "three", "chairs", "and", "two", 
    "lamps", "in",  "the", "room"];

string res = string.Empty;

words.ForEach(word => {

    res += $"{word} ";
});

Console.WriteLine(res);

The code iterates over the list using the ForEach method, appending each word and a space to the result string using the += operator.

Source

string.Join method

This tutorial has demonstrated various methods to convert a list to a string in C#.

Author

My name is Jan Bodnar, and I am a passionate programmer with extensive programming experience. I have been writing programming articles since 2007. To date, I have authored over 1,400 articles and 8 e-books. I possess more than ten years of experience in teaching programming.

List all C# tutorials.