Created
March 18, 2011 03:53
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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