c# join list to string 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# array.join
using System;
public class Demo {
public static void Main(string[] args) {
string[] strArr = {"AB", "BC", "CD", "DE", "EF", "FG", "GH", "IJ" };
Console.WriteLine("String Array...");
foreach(string s in strArr) {
Console.WriteLine(s);
}
string str = string.Join("*", strArr);
Console.WriteLine("Result (after joining) = " + str);
}
}
Example 4: c# object list to joined string
using System.Linq
string.Join(",", people.Select(x => x.surname))
Example 5: c# list to string
using System.Linq;
string str = list.Aggregate((x, y) => x + ',' + y);