Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why is List<T>.ForEach missing from .NET Core?

I was porting some code over to work with a Windows Store App and noticed that the List<T>.ForEach method isn't included in the .NET Core framework (the framework referenced by Windows Store Apps).

MSDN confirms that it is not supported for Store Apps.

I can easily get around the missing method, but at this point I'm just curious why it's missing.

like image 536
Justin Skiles Avatar asked Nov 03 '12 18:11

Justin Skiles


1 Answers

I can easily get around the missing method, but at this point I'm just curious why it's missing.

I suspect it was deemed unnecessary bloat which arguably would have been better not in the framework to start with, as using foreach is usually cleaner.

Indeed, from the link at the bottom of that blog post, MSFT provides an answer in the MSDN forums:

List<T>.ForEach has been removed in Metro style apps. While the method seems simple it has a number of potential problems when the list gets mutated by the method passed to ForEach. Instead it is recommended that you simply use a foreach loop.

like image 52
Jon Skeet Avatar answered Nov 16 '22 02:11

Jon Skeet