LINQ does not actually have ForEach (specifically). There is a List<T>.ForEach that triggers an action for each object in the list.
The main difference: All is a filter - it returns true if all elements match the predicate. List<T>.ForEach exists to create side effects - you perform some operation on each item in the list.
In general, I would avoid queries with LINQ that cause side effects (i.e. do not perform an operation in the query) and instead put them in a ForEach loop. This makes the goal very clear, which helps maintainability.
Note that List<T>.ForEach has actually been removed from WinRT, as it does not really add much value. Eric Lippert wrote a great List<T>.ForEach article using ForEach instead of List<T>.ForEach .
Reed copsey
source share