在System.Linq命名空间,我们现在可以扩展我们IEnumerable的有Any()和Count() 扩展方法.
System.Linq
IEnumerable
Any()
Count()
最近我被告知如果我想检查一个集合中是否包含一个或多个项目,我应该使用.Any()扩展方法而不是.Count() > 0扩展方法,因为.Count()扩展方法必须迭代所有项目.
.Any()
.Count() > 0
.Count()
其次,一些集合具有属性(未扩展方法),其是Count或Length.使用它们会更好吗,而不是.Any()或.Count()?
Count
Length
是啊/是?
.net linq performance extension-methods .net-3.5
.net ×1
.net-3.5 ×1
extension-methods ×1
linq ×1
performance ×1