Any and All Methods
Let’s learn how to use the
All methods to check whether a collection has elements or not. Unlike
Where, these two methods don’t return a new collection, but a
How to check if a collection has elements
Any method works with and without parameters.
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
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
How to check if all of a collection meets a condition
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.