c# list to string with separator code example

Example 1: c# list to string join

String.Join(" ", elements)

Example 2: c# list join

List<string> names = new List<string>() { "John", "Anna", "Monica" };
var result = String.Join(", ", names.ToArray());

Example 3: c# join string array

var combined = String.Join(",", new String[]{"a","b"});
// a,b

Example 4: c# list string return concatenate

string delimiter = ",";
List<string> items = new List<string>() { "foo", "boo", "john", "doe" };
Console.WriteLine(items.Aggregate((i, j) => i + delimiter + j));

Example 5: c# object list to joined string

using System.Linq

string.Join(",", people.Select(x => x.surname))