Is the Listlt;Tgt;.ForEach() method gone?(Listlt;Tgt;.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<T>.ForEach() 方法消失了吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:List<T>.ForEach() 方法消失了吗?
基础教程推荐
- 将 XML 转换为通用列表 2022-01-01
- 如何激活MC67中的红灯 2022-01-01
- 如何在 IDE 中获取 Xamarin Studio C# 输出? 2022-01-01
- c# Math.Sqrt 实现 2022-01-01
- rabbitmq 的 REST API 2022-01-01
- MS Visual Studio .NET 的替代品 2022-01-01
- 有没有办法忽略 2GB 文件上传的 maxRequestLength 限制? 2022-01-01
- SSE 浮点算术是否可重现? 2022-01-01
- 将 Office 安装到 Windows 容器 (servercore:ltsc2019) 失败,错误代码为 17002 2022-01-01
- 为什么Flurl.Http DownloadFileAsync/Http客户端GetAsync需要 2022-09-30