From the course: .NET Essentials: Working with LINQ

Unlock this course with a free trial

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

Learn how to use Any method to determine if element exists

Learn how to use Any method to determine if element exists - .NET Tutorial

From the course: .NET Essentials: Working with LINQ

Learn how to use Any method to determine if element exists

- [Instructor] The other version of Any takes a predicate as a parameter, and we use this version to determine whether there are any elements in a sequence that satisfy that predicate condition. And that it's key to remember, that Any always stops evaluating as soon as it finds any member that satisfies the condition. So here's how I've implemented it. Any returns a bullion, so I'm storing that in this variable. Here's my predicate condition. Do any of my web color color names start with the letter "C"? Let's see if that's true. So the answer is yes, and then I also wrote a query expression here that dumps out the colors that start with the letter "C". So there's eight items total, but remember, it stops evaluation as soon as it found crimson. So it doesn't have to look any further in the list. For my second example, I check to see whether any of my web colors.BlueValue is greater than or equal to 255, and I…

Contents