From the course: Complete Guide to .NET LINQ: Querying Collections, Databases, and Markup

Unlock this course with a free trial

Join today to access over 24,700 courses taught by industry experts.

Use the All method to check if all elements match

Use the All method to check if all elements match

- [Instructor] For our final quantifier operator, we'll look at 'All'. This method checks whether every element in a sequence satisfies the given predicate. Unlike 'Any', which returns true if at least one element meets the condition, 'All' requires that every element does. Let's start with this simple sequence of numbers. It's a list of ins. Then here is my call to all and I'm passing in a predicate that checks for even numbers. Run the query and that comes back every member of this list is even, so let's change that. I'll change this to 25. Press F5 to rerun the query, and now I get back false. Let's look at line 11, a more sophisticated predicate. Here I check whether all numbers in the list have exactly two digits. To do this, my predicate uses math.floor, math.log 10 and math absolute to determine if each number falls within the two digit range. So you can see right now it says it's true. So let's go ahead and change one of these to have three digits. Press F5 to rerun, and it…

Contents