2
Vote

Doesn't compile in .NET 3.5

description

The 22467 download doesn't compile for me. I receive the following errors:
 
'System.Collections.Generic.IEnumerable<int>' does not contain a definition for 'ForEach' and no extension method 'ForEach' accepting a first argument of type 'System.Collections.Generic.IEnumerable<int>' could be found (are you missing a using directive or an assembly reference?) ExtensionOverflowTests\LinqExtensionsTest.cs 30 19 ExtensionOverflowTests
 
 
'System.Collections.Generic.IEnumerable<int>' does not contain a definition for 'ForEach' and no extension method 'ForEach' accepting a first argument of type 'System.Collections.Generic.IEnumerable<int>' could be found (are you missing a using directive or an assembly reference?) ExtensionOverflowTests\LinqExtensionsTest.cs 44 19 ExtensionOverflowTests
 
public class LinqExtensionsTest
...
public void ForEachAction()
...
@enum.ForEach(n => sum += n); // <-- FAIL
 
 
public void ForEachFunc()
...
@enum.ForEach(n => sum += n); // <-- FAIL
 
 
There no ForEach() extension method defined for IEnumerable<T> in System.Linq.Enumerable for .NET 3.5.
 
I added the following code to make it compile:
 
    public static void ForEach<T>(this IEnumerable<T> source, Action<T> action)
    {
        foreach (var item in source)
        {
            action(item);
        }
    }
 
(I haven't tested it to make sure it works though.)
 
Am I doing something wrong? Am I missing something?

comments