What is the most elegant way to return a string from a List
ok, yeah, I know I can do something like
public string Convert(List<int> something)
{
var s = new StringBuilder();
foreach(int i in something)
s.AppendFormat("{0} ", i);
return s.ToString();
}
but i m sure there is a way to do this with lambdas
I tried also to append to a stringbuilder but that is not doing whats expected
IMO, you were better off with your original version; LINQ is great, but it isn’t the answer to every problem. In particular, the
string.Joinapproach demands an extra array (for little gain), and theAggregateapproach uses lots of intermediate strings.Perhaps make it an extension method, though – and lose the
Formatstuff: