Creating your own LINQ extension methods
In Chapter 7, 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.
Tip
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.
In either Visual Studio 2017 or Visual Studio Code, open the Ch09_LinqToObjects
project or folder, and add a new class file named MyLINQExtensions.cs
.
Modify the class to look like the following code. Note that the ProcessSequence
extension method doesn't modify the sequence because it exists only as an example. It would be up to you to process the sequence in whatever manner you want. The SummariseSequence
extension method also doesn't do anything especially useful. It simply returns a long
count of the number of items in the sequence using the built-in LongCount
extension method. Again, it would...