是List< T> .ForEach()方法到哪里去了?去了、方法、到哪里、LT

2023-09-02 10:30:55 作者:乍见之欢

我开始涉足Windows 8的地铁最近,发现我的老哥们人似乎失踪了。

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

我倾向于使用 .ForEach()方法比我更使用传统的foreach()结构,我很快就意识到pretty的,这个方法不可用。例如,该code不会在一个地铁的应用程序编译:

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?

推荐答案

It's的确走了:

名单,其中,T&GT; .ForEach已在Metro风格的应用程序中删除。而该方法看似简单它有许多潜在的问题当列表被通过传递给的ForEach方法突变。相反,我们建议您只需使用一个foreach循环。

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.

韦斯·哈格德| .NET框架小组(BCL)| http://blogs.msdn.com/b/bclteam/

Wes Haggard | .NET Framework Team (BCL) | http://blogs.msdn.com/b/bclteam/

很奇怪,但是,它使在文档的外观,其中无处它指出,这种方法不支持.NET为Windows应用商店的应用程序(以前.NET的Metro风格的应用程序)。也许这仅仅是对文档团队的一员的监督。

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.