You want to build a comma-separated list of numbers from 1 to 5 using StringBuilder. Which code snippet is the most efficient and correct?
Avar sb = new StringBuilder();
for(int i=1; i<=5; i++) {
sb.Append(i).Append(",");
}
sb.Remove(sb.Length - 2, 1);
Console.WriteLine(sb.ToString());
Bvar sb = new StringBuilder();
for(int i=1; i<=5; i++) {
sb.Append(i);
if(i < 5) sb.Append(",");
}
Console.WriteLine(sb.ToString());
Cvar sb = new StringBuilder();
sb.Append("1,2,3,4,5,");
Console.WriteLine(sb.ToString());
Dvar sb = new StringBuilder();
for(int i=1; i<=5; i++) {
sb.Append(i + ",");
}
Console.WriteLine(sb.ToString());