After using C# 3.0 and Linq for a while, one can see how the IEnumerable interface has been empowered by the use of extension methods.

However, there is one extension method that is notoriously missing : IEnumerable.ForEach.

Here how to use it with Umbrella, and execute a simple action :

        .Range(0, 10)
        .ForEach(item => Console.WriteLine(item + 1));

It is also possible to specify an action that will take the index of the element being enumerated :

    new []{ "A", "B", "C" }
            (index, item) => Console.WriteLine("{0}: {1}", index, item)

Last edited Feb 24, 2009 at 3:44 AM by jlaban, version 1


No comments yet.