What is the tersest way to transform an integer array into a string enumerating the elements inline? I’m thinking something like an anonymous function that performs the conversion.
var array = new int[] { 1, 2 }
var s = string.Format("{0}",
new []
{ /*inline transform array into the string "1, 2"*/ });
Use
string.Join. In .NET 3.5 and earlier you need to convert to a string array first; in .NET 4 there’s an overload takingIEnumerable<T>. So depending on your version:.NET 2.0 or 3.0 / C# 2:
.NET 2.0 or 3.0 / C# 3:
.NET 3.5 / C# 3:
(or use the version which works with .NET 2.0 if you prefer).
.NET 4:
(I hadn’t even seen that before today!)