O'Reilly logo

Instant .NET 4.5 Extension Methods How-to by Shawn R. McLean

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Extension methods on enumerables (Should know)

Now, we move on to where extension methods are used the most, enumerated types. In an article by Eric Lippert, a principal developer on the C# team; LINQ was the reason extension methods were created in the first place. In this recipe, we will look at writing our own extension methods for the IEnumerable and IList type and take a look at an existing extension method in the .NET framework from the LINQ namespace.

Getting ready

Refer to the IEnumerableExtensions.cs and IListExtensions.cs file in the ExtensionMethods.Library project for the extension methods. These methods are used in the IEnumerableExtensionTests.cs file in the ExtensionMethods.Tests project.

How to do it...

The following code snippet ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required