Skip to content

Instantly share code, notes, and snippets.

@aliostad
Created June 25, 2012 20:29
Show Gist options
  • Save aliostad/2991023 to your computer and use it in GitHub Desktop.
Save aliostad/2991023 to your computer and use it in GitHub Desktop.
ForEachOne for IEnumerable<T> not having to use ToList().ForEach()
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