LINQ's ForEach doesn't work on IEnumerable

2009-03-29 09:39:45 +0000

For some reason, LINQ’s ForEach extension method doesn’t work on IEnumerable; it only works on IList. Easy fix:

public static class EnumerableExtensions
{
    public static void ForEach(this IEnumerable values, Action action)
    {
        foreach (var value in values)
        {
            action(value);
        }
    }
}</pre>