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 Where method

The Where method

- [Instructor] The WHERE clause filters a sequence based on a predicate function. That predicate function is applied to each element in the sequence. So as programmers, when we're writing a query, we have to write a predicate that is used to determine which items in the sequence belong in the output sequence. This is the typical syntax using the query expression. You use the where keyword here, and then this is where you'd put your predicate function. Typically, WHERE clauses go near the top of your query, but that's not a requirement. Now what I've said here is where false. This essentially says, I don't want any items back when I run the query, zero items. If I switched this to true, how many items do you think will be returned in this query? Right, all of them. All 140 web colors. So to make this more useful, I'll switch this out and I'll use a property on the web color class, like this. I can use any of these…

Contents