C# – LINQ Any Examples

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.