List<T>.ForEach() 方法消失了吗? [英] Is the List<T>.ForEach() method gone?

查看:21
本文介绍了List<T>.ForEach() 方法消失了吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我最近开始涉足 Windows 8 Metro,发现我的一个老朋友似乎失踪了.

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

我更倾向于使用 .ForEach() 方法而不是使用传统的 foreach() 构造,并且我很快意识到这种方法不可用.例如,此代码不会在 Metro 应用程序下编译:

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?

推荐答案

确实没了:

List<T>.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 for Windows Store 应用程序(以前是 Metro 风格应用程序的 .NET)不支持此方法.也许这只是部分文档团队的疏忽.

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.

这篇关于List&lt;T&gt;.ForEach() 方法消失了吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆