在.NET中,是它更好地调用.Count之间()或可用时,.Count之间?或可、更好地、NET、Count

2023-09-06 05:55:25 作者:゛梦晓ヶ微光ヅ倾城

在LINQ的命名空间是进口的,也可以同时使用.Count之间()和.Count之间(在该实现IList例如对象)。

When the Linq namespace is imported, it is possible to use both .Count() and .Count (on objects that implement IList for example).

.Count之间()将调用.Count之间的财产,如果有的话,按: C#伯爵()扩展方法效果

.Count() will call the .Count property, if available, as per: C# Count() Extension Method Performance

它是更好然后直接用.Count之间超过.Count之间的(),对于一个(小)性能提升?

Is it better then to directly use .Count over .Count(), for a (small) performance gain?

更新:这里有趣的业绩数字(1-2个数量级):Is LINQ的计数()比List.Count快或慢,或Array.Length?

Update: interesting performance figures here (1-2 orders of magnitude): Is the Linq Count() faster or slower than List.Count or Array.Length?

推荐答案

我个人的preference与现有的方法和属性来坚持,如果他们都可以无需进行转换。因此,我会使用计数

My personal preference is to stick with the existing methods and properties if they are available without casting. Therefore I'd use Count.

 
精彩推荐
图片推荐