Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

6
  • Fair enough. What about the use of the .Count property then? wouldn't that make the read significantly faster, maybe as fast or even faster than calling .Any() ? Commented Sep 4, 2015 at 18:29
  • 5
    With a List<T> the performance difference will be negligible. So just use what you prefer. But for other types of IEnumerables, you only get to pick between Count() (the method), and Any(), and in that case, Any() will always be the clear winner for your use case and should be preferred. For what it's worth, I think Any() is quite readable and clear. Commented Sep 4, 2015 at 18:34
  • @sstan yes unless if the ienumerable can be cast to a collention then it can be optimized and it won't matter. Commented Sep 4, 2015 at 19:10
  • 2
    Count() has the same complexity as Count for ICollections, since the extension method then uses the property instead of iterating. Commented Sep 5, 2015 at 7:38
  • Linq extensions are optimised for known interfaces - IList , ICollection. Performance discussion here is totally redundant, even if that is an implementation detail Commented Sep 5, 2015 at 17:20