I’ve seen a lot of extension methods that allowed you to create a list of comma separated values.
I even created a similar extension method myself until I discovered the String.Join method while reading this blog post by Scott Hanselman:
public static string ToCSV(this IEnumerable<string> input)
{
var temp = String.Empty;
foreach (var entry in input) {
if (String.IsNullOrEmpty(temp)) {
temp = entry;
}
else
{
entry += ", " + entry;
}
return temp;
}
I even created a similar extension method myself until I discovered the String.Join method while reading this blog post by Scott Hanselman:
var temp = String.Join(", ", input)