List.All()和List.TrueForAll()之间的区别 [英] Difference between List.All() and List.TrueForAll()

查看:1872
本文介绍了List.All()和List.TrueForAll()之间的区别的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

List上进行操作时,.All().TrueForAll()之间是否存在实际差异?我知道.All()IEnumerable的一部分,那么为什么要添加.TrueForAll()?

解决方案

来自 List<T>.TrueForAll 的文档:

支持:4、3.5、3.0、2.0

因此它是在之前 Enumerable.All添加的.

对于其他许多List<T>方法也是如此,这些方法的工作方式与LINQ方法类似.请注意,ConvertAll有所不同,因为它具有了解的优势,即它正在处理List<T>并创建List<TResult>,因此可以预先分配所需的内容.

Is there a practical difference between .All() and .TrueForAll() when operating on a List? I know that .All() is part of IEnumerable, so why add .TrueForAll()?

解决方案

From the docs for List<T>.TrueForAll:

Supported in: 4, 3.5, 3.0, 2.0

So it was added before Enumerable.All.

The same is true for a bunch of other List<T> methods which work in a similar way to their LINQ counterparts. Note that ConvertAll is somewhat different, in that it has the advantage of knowing that it's working on a List<T> and creating a List<TResult>, so it gets to preallocate whatever it needs.

这篇关于List.All()和List.TrueForAll()之间的区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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