Created
April 18, 2012 05:01
-
-
Save huobazi/2411195 to your computer and use it in GitHub Desktop.
IEnumableExtensions
This file contains hidden or 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 class IEnumableExtensions | |
{ | |
public static void ForEach<T>(this IEnumerable<T> value, Action<T> action) | |
{ | |
foreach (var v in value) | |
{ | |
action(v); | |
} | |
} | |
public static string Join<T>(this IEnumerable<T> collection, string separator) | |
{ | |
if (!collection.Any()) | |
{ | |
return string.Empty; | |
} | |
StringBuilder sb = new StringBuilder(); | |
collection.ForEach(e => sb.Append(e.ToString() + separator)); | |
return sb.ToString().Substring(0, sb.Length - separator.Length); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment