Any and All Methods

Learn how to filter a collection with the Any and All methods.

Let’s learn how to use the Any and All methods to check whether a collection has elements or not. Unlike Select and Where, these two methods don’t return a new collection, but a boolean result.

How to check if a collection has elements

The Any method works with and without parameters.

The Any method, without parameters, checks if a collection is empty. If a collection has at least one element, the Any method returns true. But if the collection is empty, it returns false.

When we pass a condition to the Any method, it checks if a collection has at least one element matching that condition. It also returns either true or false.

How to check if all of a collection meets a condition

The Any method checks for at least one element in a collection. But what if we want to check for all elements in a collection?

The answer to that question is the All method. As its name implies, the All method returns true only if every element in a collection satisfies a condition.

Let’s find out if we’ve only watched really good movies.

Get hands-on with 1200+ tech skills courses.