Geeks With Blogs
Abhishek Anand Bits & Bytes about .net technology framework.

The Any method is an expression that will check the collection that was called on to see if there are “any” elements matching the given criteria. Criteria can be provided as a predicate (function/lambda expression resulting in a Boolean value) to the Any method as a parameter. When no parameters are provided, .Any() checks to see if there are elements in the collection. 


For this reason, .Any() is preferred over .Count() > 0.

Posted on Monday, November 18, 2013 6:13 PM .net , linq | Back to top


Comments on this post: .Any() vs. .Count() > 0

# re: .Any() vs. .Count() > 0
Requesting Gravatar...
That's not the reason why. The reason why is Any will terminate early on the first detection of anything. Count has to evaluate the entire enumeration to find out how many there are.
Left by Keith on Nov 19, 2013 2:21 AM

Your comment:
 (will show your gravatar)


Copyright © Abhishek Anand | Powered by: GeeksWithBlogs.net