Click here to Skip to main content
15,887,135 members
Articles / Programming Languages / C#

Replacing foreach loop with LINQ

Rate me:
Please Sign up or sign in to vote.
4.33/5 (6 votes)
23 Oct 2011CPOL 118.2K   2  
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;});

Views

Daily Counts

License

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


Written By
Software Developer
Israel Israel
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions