Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
167 views
in Technique[技术] by (71.8m points)

c# - Is the List<T>.ForEach() method gone?

I started dabbling in Windows 8 metro recently, and found that one of my old buddies seems to have gone missing.

I tend to use the .ForEach() method more than I use the traditional foreach() construct, and I realized pretty quickly that this method isn't available. For example, this code will not compile under a metro app:

var list = new List<string>();

list.ForEach(System.Diagnostics.Debug.WriteLine);

I've searched to see if I could find any discussion of this, but wasn't able to. Am I just being obtuse, or is it actually gone?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

It's indeed gone:

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/

Very strangely, however, it makes an appearance in the documentation, in which nowhere does it state that this method isn't supported in .NET for Windows Store apps (formerly .NET for Metro-style apps). Perhaps this is just an oversight on part of the documentation team.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...