在.NET中,是它更好地调用.Count之间()或可用时,.Count之间? [英] In .NET, is it better to call .Count() or, when available, .Count?

查看:149
本文介绍了在.NET中,是它更好地调用.Count之间()或可用时,.Count之间?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在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个数量级):<一href="http://stackoverflow.com/questions/981254/is-the-linq-count-faster-or-slower-than-list-count-or-array-length/985279#985279">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.

这篇关于在.NET中,是它更好地调用.Count之间()或可用时,.Count之间?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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