CSharpFeeds - All your C# feeds in one place.

Sponsors

Wednesday, February 25, 2009

ForEach or not ForEach, that is the question

by Fabrice Marguerie via Fabrice's weblog on 2/25/2009 6:20:00 PM

In LINQ in Action, we discuss about the missing ForEach query operator. This is in Chapter 5 "Beyond basic in-memory queries", more precisely in section 5.2.2. There, we indicate that Eric White suggested this operator in his functional programming tutorial, although I'm not able to find the exact reference at the moment in this tutorial.

Since then, a lot of people have been asking for ForEach. This can be seen on Kirill Osenkov's blog, where you'll find links to discussions about whether ForEach is good or bad.
I don't know if we're going to see ForEach appear in .NET. Anyway, it's not very difficult to write your own:

public static void ForEach<T>(this IEnumerable<T> source, Action<T> action)
{
  if (source == null)
    throw new ArgumentNullException("source");
  if (action == null)
    throw new ArgumentNullException("action");

  foreach (var item in source)
    action(item);
}

Cross-posted from http://LinqInAction.net

email it!bookmark it!digg it!

Original Post: ForEach or not ForEach, that is the question

Subscribe

New Feed

Product Spotlight

Recently Updated Sources

Legal Note

The content of the postings is owned by the respective author. CSharpFeeds is not responsible for the contents of the postings. This site is automatically generated and cannot be reviewed for abusive content. If you find abusive content on CSharpFeeds, please contact us. Designated trademarks and brands are the property of their respective owners. All rights reserved.

Advertise with us