Nitin Taneja

I can think of nothing less pleasurable than a life devoted to pleasure !!

Tuesday, March 20, 2012

LINQ equivalent of foreach for IEnumerable

There is no ForEach extension for IEnumerable as it is only for List. So you could do

This is not working -
IEnumerable items = GetItems();
items.ForEach(i => i.DoStuff());


You can add tolist before doing foreach -

items.ToList().ForEach(i => i.DoStuff());
Posted by Nitz at 11:18 PM

No comments:

Post a Comment

Newer Post Older Post Home
Subscribe to: Post Comments (Atom)

Blog Archive

  • ►  2014 (1)
    • ►  04/27 - 05/04 (1)
  • ►  2013 (1)
    • ►  09/01 - 09/08 (1)
  • ▼  2012 (5)
    • ►  09/16 - 09/23 (1)
    • ▼  03/18 - 03/25 (1)
      • LINQ equivalent of foreach for IEnumerable
    • ►  02/19 - 02/26 (1)
    • ►  02/12 - 02/19 (1)
    • ►  01/15 - 01/22 (1)
  • ►  2011 (9)
    • ►  10/02 - 10/09 (1)
    • ►  09/04 - 09/11 (1)
    • ►  08/21 - 08/28 (1)
    • ►  08/14 - 08/21 (1)
    • ►  07/17 - 07/24 (1)
    • ►  06/12 - 06/19 (2)
    • ►  05/29 - 06/05 (1)
    • ►  05/22 - 05/29 (1)
  • ►  2010 (11)
    • ►  11/28 - 12/05 (1)
    • ►  11/21 - 11/28 (2)
    • ►  11/14 - 11/21 (1)
    • ►  11/07 - 11/14 (3)
    • ►  10/31 - 11/07 (4)
  • ►  2008 (3)
    • ►  10/12 - 10/19 (1)
    • ►  09/21 - 09/28 (1)
    • ►  06/22 - 06/29 (1)
  • ►  2006 (2)
    • ►  06/11 - 06/18 (1)
    • ►  04/23 - 04/30 (1)

About Me

Nitz
View my complete profile

Links

  • Google News
  • Edit-Me
  • Edit-Me
  • Sandy's blog
  • Sumit's blog
  • Minal's blog
  • NobodysDevil blog
Simple theme. Theme images by gaffera. Powered by Blogger.