Skip to content

Instantly share code, notes, and snippets.

@Nilzor
Created January 18, 2012 16:53
Show Gist options
  • Save Nilzor/1634007 to your computer and use it in GitHub Desktop.
Save Nilzor/1634007 to your computer and use it in GitHub Desktop.
Converts an IEnumerable list to a comma separated list of string
/// <summary>
/// Prints the collection as a comma separated string
/// </summary>
public static string ToStringList<T>(this IEnumerable<T> list)
{
if (list == null) return String.Empty;
var sb = new StringBuilder();
foreach (var elem in list)
{
if (elem == null) continue;
sb.Append(elem.ToString());
sb.Append(", ");
}
if (sb.Length >2) sb.Remove(sb.Length - 2, 2);
return sb.ToString();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment