most elegant way to return a string from List<int>
c#
Solution
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.Join` approach demands an extra array (for little gain), and the `Aggregate` approach uses lots of intermediate strings.
Perhaps make it an extension method, though - and lose the `Format` stuff:
public static string Concatenate<T>(this IEnumerable<T> source, string delimiter)
{
var s= new StringBuilder();
bool first = true;
foreach(T t in source) {
if(first) {
first = false;
} else {
s.Append(delimiter);
}
s.Append(t);
}
return s.ToString();
}
Problem
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