From the course: .NET Essentials: Working with LINQ

Unlock this course with a free trial

Join today to access over 22,400 courses taught by industry experts.

The All method

The All method

- [Narrator] For our last quantify operator, we're going to look at all. And we use that to return whether or not all the elements in the sequence master, given predicate. So they all have to match the predicate, not just one of them. That's the key here. So for my first example, I work with this list of integers and I'm checking whether they're all even numbers. So I pass in a predicate for the test. Let's run that. I get back, they're all even numbers, is true. If I make this one, let's change one of the values, run it again. I should get back false. And here's a slightly more sophisticated test. I'm checking whether the numbers have two digits by using this formula. So my predicate uses the Math.floor Math.log10 and Math.abs or absolute to determine whether they have two digits or not. So right now it says true. Let's make this value 140 and then run again. And I get back false. So useful, if you want to…

Contents