#1,171 – Lambda Expression Internals

Suppose that we have the following lambda expression (doubles a number) and that we invoke it.

    class Program
        static void Main(string[] args)
            Func<int, int> intDoubler = x => 2 * x;

We can compile this code and then use the IL Disassembler to inspect the resulting IL.

We can see that in our main class we have a static Main method and also a private static method defined by the compiler to contain our lambda expression.  In this case, it’s named <Main>b__0.


Cracking open Main() reveals that it indeed calls <Main>b__0.


And looking at the body of <Main>b__0, we can see that it indeed just doubles the input parameter.