Any is LINQ functionality to validate whether collection contains at least one element which meets given criteria.
Let’s start with example collection of integers:
First call the Any function without any parameter, which means we check if integers collection contains at least one element:
Print a result to the console:
Result:
As we can see the result is True because collection is not empty.
Now let’s use Any function with two different filtering criteria: first checks if collection contains items greater than 10, and second checks if collection contains items lower than 0.
Result:
First query returns True because there is at least one element greater than 10 (actually there are two such elements). Second query returns False because there are no items in the collection lower than 0.
Need Help with Your C# Projects?
We offer expert support and development services for projects of any size. Contact us for a free consultation and see how we can help you succeed.
CONTACT US NOW