Why does List<T>.ForEach() implement a for loop?

Viewed 1258

I don't understand why the List<T>.ForEach() extension method implements a for loop under the hood. This opens up the possibility of the collection being modified. A normal foreach will throw an exception in this case so surely ForEach() should react the same way?

If you MUST mutate a collection for whatever reason, then surely you should be manually iterating through the collection in a for loop?

There seems to be a bit of a semantic contradiction here between foreach and List<T>.ForEach().

Am I missing something?

3 Answers
Related