Skip to content

Instantly share code, notes, and snippets.

@Nilzor
Created January 18, 2012 15:53
Show Gist options
  • Save Nilzor/1633668 to your computer and use it in GitHub Desktop.
Save Nilzor/1633668 to your computer and use it in GitHub Desktop.
Converts an ICollection of T to a comma separated list of strings
/// <summary>
/// Prints the collection as a comma separated string
/// </summary>
public static string ToStringList<T>(this ICollection<T> list)
{
var sb = new StringBuilder();
int i = 0;
foreach (var elem in list)
{
sb.Append(elem.ToString());
if (i++ != list.Count - 1) sb.Append(", ");
}
return sb.ToString();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment