Skip to content

Instantly share code, notes, and snippets.

@amirci
Created March 18, 2011 03:53
Show Gist options
  • Save amirci/875598 to your computer and use it in GitHub Desktop.
Save amirci/875598 to your computer and use it in GitHub Desktop.
Extensions to Join all the elements in the collection calling the functor and using separator
public static string Join<T>(this IEnumerable<T> collection, char separator, Func<T, string> fn)
{
return collection
.Head()
.Aggregate(new StringBuilder(), (b, x) =>
{
b.Append(fn(x));
b.Append(separator);
return b;
})
.Append(collection.Last())
.ToString();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment