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.

Extension methods

Extension methods

- [Male Narrator] It's time for another essential concept in LINQ, and I'm talking about extension methods. All of the LINQ operators that are implemented in the enumerable type are implemented as extension methods. So, it's important for us to review what they are, how you create one, and how you call an extension method. We'll start by looking at the code in void main. Now, I'm using the program feature of LINQPad so I can write a main method and I can also add some of my own classes in this demo. And the first thing I want to point out is I'm working with two instances of types here, a list of string and an array of integers. And both of these implement I Enumerable. Also, list of string implements IEnumerable of T. What I want to do is, I want to write an extension method that extends any type that implements I Enumerable T. And the reason I'm doing that is because that's how a lot of the LINQ operators work. They extend the…

Contents