skip to content
Khalid Abuhakmeh logo Khalid Abuhakmeh

string.Join

.NET Framework 4

Code card: string.Join. Program output: John, Paul, George, Ringo / 1 + 4 + 9 + 16

string.Join takes any separator and any IEnumerable<T>, including LINQ results. It is available since .NET Framework 4. The key line is Console.WriteLine(string.Join(", ", band)) in join.cs. Run it and the output reads John, Paul, George, Ringo, 1 + 4 + 9 + 16.

Did this tip save you some time? Consider buying me a coffee to fuel the next one.

Buy me a coffee
join.cs
string[] band = ["John", "Paul", "George", "Ringo"];
Console.WriteLine(string.Join(", ", band));
var sq = Enumerable.Range(1, 4).Select(n => n * n);
Console.WriteLine(string.Join(" + ", sq));
Output
$ dotnet run join.cs
John, Paul, George, Ringo
1 + 4 + 9 + 16