Tip #011
string.Join
About this tip
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 coffeeCode
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.csJohn, Paul, George, Ringo1 + 4 + 9 + 16