Click here to Skip to main content
11,708,312 members (64,969 online)
Click here to Skip to main content

Tagged as

Replacing foreach loop with LINQ

, 23 Oct 2011 CPOL 23.4K 2
Rate this:
Please Sign up or sign in to vote.
For replacing foreach loop, for a non-query operation, just for performing an operation on each element in the collection, we can use the ForEach method, like the following:students.ToList().ForEach(s => { s.Grade += 10;});

For replacing foreach loop, for a non-query operation, just for performing an operation on each element in the collection, we can use the ForEach method, like the following:

students.ToList().ForEach(s => 
{
    s.Grade += 10;
});

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

Shmuel Zang
Software Developer
Israel Israel
No Biography provided

You may also be interested in...

Comments and Discussions

 
SuggestionCaveat: performance Pin
Member 819890211-Feb-15 21:46
memberMember 819890211-Feb-15 21:46 
GeneralRe: Caveat: performance Pin
Shmuel Zang17-Feb-15 22:39
memberShmuel Zang17-Feb-15 22:39 
GeneralReason for my vote of 3 Doesn't read as clearly to me as som... Pin
Pong God25-Oct-11 11:49
memberPong God25-Oct-11 11:49 
GeneralWas actually expecting the ForEach Extension Method in the o... Pin
Naerling23-Oct-11 2:15
memberNaerling23-Oct-11 2:15 
GeneralRe: I didn't include the ForEach Extension method because it's n... Pin
Dan De'lashmate23-Oct-11 6:23
memberDan De'lashmate23-Oct-11 6:23 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Terms of Use | Mobile
Web01 | 2.8.150819.1 | Last Updated 23 Oct 2011
Article Copyright 2011 by Shmuel Zang
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid