Invoking Extension Methods Statically
Recall that the first parameter of an extension method is marked with the this keyword, followed by
the type of item the method is applicable to. If we peek at what is happening behind the scenes (as
verified by a tool such as ildasm.exe), we will find that the compiler simply calls the “normal” static
method, passing in the variable calling the method as a parameter (e.g., it is the value of this). Con-
sider the following C# code, which approximates the code substitution that took place:
private static void Main(string[] args)
{
Console.WriteLine("***** Fun with Extension Methods *****\n");
int myInt = 12345678;
Do'stlaringiz bilan baham: |