Created
June 25, 2012 20:29
-
-
Save aliostad/2991023 to your computer and use it in GitHub Desktop.
ForEachOne for IEnumerable<T> not having to use ToList().ForEach()
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
using System; | |
using System.Collections.Generic; | |
using System.Linq; | |
namespace System.Collections.Generics | |
{ | |
public static class IEnumerableExtensions | |
{ | |
public static IEnumerable<T> ForEachOne<T>(this IEnumerable<T> enumerable, Action<T> action) | |
{ | |
foreach (var t in enumerable) | |
{ | |
action(t); | |
yield return t; | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment