How many times did you need to join a collection of strings (to create an CSV file, for instance) and ended up doing something like this:
string GetLines(string[] values){
StringBuilder result = new StringBuilder();
int i;
for(i = 0; i < values.Length - 1; i++)
{
result.AppendFormat("{0},", values[i]);
}
result.Append(values[i]);
return result.String();
}
There is a method for that! It is called Join and it is a static method in the String class:
String.Join(string separator, string[] values)
P.S: I know I should have read the documentation of the .NET Framework. But I haven’t done that before for the String class. I wonder how many times I have writen a method like this since I started programming.
