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 the Enumerable extension methods

Learn how to use the Enumerable extension methods - .NET Tutorial

From the course: .NET Essentials: Working with LINQ

Learn how to use the Enumerable extension methods

- [Instructor] The extension method syntax simplifies the code, and it makes it easier, I think, to understand your intent. Here is the old version of the Where using the static method, Enumerable.Where, and then it takes two arguments, the colors instance and the lambda expression. The new syntax, you move the colors instance to the front of the expression, and you do .Where. You only have to pass a single argument into the Where method. That's the lambda expression. I think one of the main reasons it was added to .NET is to simplify this and also make it easier to string together function calls like this called pipelining. We'll look at that more later. Here is the old code for working with Last, Enumerable.Last colors. Here's the new syntax, colors.Last. I think that's a little bit more readable. And then as I said, it makes it easier to pipeline items. So here I can say colors.Where and then .Last. This would be…

Contents