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,900 courses taught by industry experts.

Using Enumerable static methods

Using Enumerable static methods

- [Instructor] At the top of the code, I'm declaring a list of strings and filling it with some color names. Since we know that list of string implements I enumerable T, that means we can query it using Linq extension methods, which are part of the enumerable class. And before we dive into the query itself, let's dump out the original values. Here we see the originalist has 11 items, 11 color strings. In Linq filtering is done using the where method. Here's how it works. So I'm going to call it because it's a method on the enumerable class, I'm going to call it directly. It's a static method, so I can say enumerable.where. The first argument is the collection that implements I enumerable T. In this case it's my colors list. The second argument is a predicate function, which determines whether each item should be included in the output. Where takes an I enumerable of T as input, it also returns an I enumerable of T, meaning we can get back a filtered list. So this variable, when we run…

Contents