This post will discuss how to convert a list to a string in C# where individual elements of the list are joined into a single string using a given delimiter. The delimiter should not be added before or after the list.

1. Using String.Join() method

The recommended solution is to use the String.Join() method of the string class, which joins elements of the specified array or collection together with the specified delimiter.

Download  Run Code

2. Using Enumerable.Aggregate() method

Like the above method, LINQ provides the Aggregate() method, which can join elements of a list using a delimiter. The following code example shows how to implement this:

Download  Run Code

3. Using StringBuilder

A naive solution is to loop through the list and concatenate each list element to the StringBuilder instance with the specified delimiter. Finally, we return the string representation of the StringBuilder. Note that the solution handles trailing delimiters’ characters.

Download  Run Code

That’s all about converting a List to a String using a delimiter in C#.