locked
Where is List<T>.ForEach()

    Question

  • Seems that List<T>.ForEach() is gone or perhaps it's moved somewhere?

    ---bjorn

     


    ---bjorn
    Saturday, September 24, 2011 10:48 PM

Answers

  • 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.


    Wes Haggard | .NET Framework Team (BCL) | http://blogs.msdn.com/b/bclteam/
    Sunday, September 25, 2011 9:16 PM

All replies

  • This is still an early version on VS11 and the whole WinRT framework. Not all things re supported yet and more things will  added overtime.

    Regards,

    Dylan Meeus


    0x2B |~ 0x2B Blog : www.it-ca.net/blogdylan
    Sunday, September 25, 2011 2:25 AM
  • Very strange.  It's listed in the documentation for .NET 4.5:  http://msdn.microsoft.com/en-us/library/bwabdf9z(v=VS.110).aspx


    Robert Levy
    Sunday, September 25, 2011 2:22 PM
  • It is in fact gone according to this documentation: http://msdn.microsoft.com/en-us/library/windows/apps/system.linq.enumerable.aspx


    -SDET @ Windows, REX
    Sunday, September 25, 2011 7:22 PM
  • 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.


    Wes Haggard | .NET Framework Team (BCL) | http://blogs.msdn.com/b/bclteam/
    Sunday, September 25, 2011 9:16 PM
  • We were taught from .Net 1.0 (or wherever the 'foreach' keyword first existed) not to change the contents of a collection within its own iterator. 

    This removal is a bit suprising, and in a good-natured way I'd like to say that it's insulting.  While I appreciate the reasoning offered by Microsoft, I like to highlight the negative developer experience of having to try to find the reason on his own, rather than some more obvious documentation. First it looks like an intellisense bug. He checks his using statements. He finds it still documented under List<T> in 4.5....maybe the assemblies got split up...etc...etc...

    You have so many articles and blogs out there about developing for Windows 8...just throw it out there as a sidebar in one of the tutorials... Another option would have been to deprecate it for one release.

    - Mike

    Monday, March 04, 2013 12:42 AM
  • Hi Mike,

    The documentation you reference for List<T> indicates that ForEach is not supported for Windows Store apps. Note that it is not marked with the green store icon labeled "Supported in .Net for Windows Store apps". Likewise, if you go to the ForEach page itself it does not say it is valid for Windows Store apps.

    You can also use the Object Viewer in Visual Studio to see what classes and methods are available for your solution type.

    --Rob

    Wednesday, March 06, 2013 5:51 AM
    Owner