In Chapter 6, Implementing Interfaces and Inheriting Classes, you learned how to create your own extension methods. To create LINQ extension methods, all you must do is extend the IEnumerable<T> type.
Good Practice
Put your own extension methods in a separate class library so that they can be easily deployed as their own assembly or NuGet package.
Put your own extension methods in a separate class library so that they can be easily deployed as their own assembly or NuGet package.
In either Visual Studio 2017 or Visual Studio Code, open the LinqWithEFCore project or folder, and add a new class file named MyLINQExtensions.cs.
We will look at the Average extension method as an example. Any school child will tell you that average can mean one of three things:
- Mean: Sum the numbers and divide by the count
- Mode: The most common number
- Median: The number in the middle of the numbers when ordered
The Average extension method actually calculates the mean. We might want to...