O'Reilly logo

C# 5.0 Unleashed by Bart De Smet

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

Introduced in C# 3.0 as part of the Language Integrated Query (LINQ)-enabling language feature set, extension methods provide a means to extend an existing type (such as a class, struct, interface, enum, delegate) with additional methods that can be invoked as if they were instance methods. Basically, they provide user convenience for calling helper methods.

Prior to .NET 3.5 (which carried C# 3.0 and VB 9.0, both with extension methods as a language feature), it was rather cumbersome to define additional functionality on an existing type if you didn’t own that type. For example, assume you got some urgent need for a method to reverse a string. Wouldn’t it be great to be able to write the next piece of code to do so?

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