Created
July 20, 2013 00:17
-
-
Save AlexArchive/6043251 to your computer and use it in GitHub Desktop.
ForEach Extension Method
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 class AutomaticIterator | |
{ | |
public static void ForEach<T>(this IEnumerable<T> iterable, Action<T> action) | |
{ | |
var iterator = iterable.GetEnumerator(); | |
using (iterator) | |
{ | |
while (iterator.MoveNext()) | |
{ | |
action(iterator.Current); | |
} | |
} | |
} | |
} | |
... | |
var collection = new[] { 10, 20, 30 }; | |
collection.ForEach(Console.WriteLine); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment