This post will discuss how to concatenate all list elements into a string in C#.

1. Using String.Join Method

A simple solution to concatenate all the members of a list into a string is using the String.Join method. The member elements are delimited using the specified separator. Note that separator is included in the returned string only if the list contains more than one element.

The following code demonstrates the usage of the String.Join method to concatenate all the items of a list using a comma as a separator.

Download  Run Code

2. Using Enumerable.Aggregate Method

Alternatively, you can use the Enumerable.Aggregate() method from LINQ to concatenate all items of a list. It applies an accumulator function over a sequence. Here’s an example of its usage to concatenate list elements using a comma as a delimiter.

Download  Run Code

That’s all about concatenating all list elements into a string in C#.