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

How the Compiler Marks and Finds Extension Methods

Two more questions can be raised about the implementation of extension methods at the level of the compiler. Both those questions relate to the bookkeeping done to mark extension methods and find them during overload resolution.

As with most post-C# 2.0 language features, extension methods are syntactical sugar on top of runtime primitives, introduced to provide more developer convenience. To implement those features, the runtime didn’t have to change at all. This can be seen clearly in the code emitted for our Reverse extension method call:

var input = Console.ReadLine();Console.WriteLine(input.Reverse());

The preceding code is turned into this:

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