#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;
            Console.WriteLine(intDoubler(12));
        }
    }

1171-001
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.

1171-002

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

1171-003

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

1171-004

About Sean
Software developer in the Twin Cities area, passionate about software development and sailing.

One Response to #1,171 – Lambda Expression Internals

  1. Pingback: Dew Drop – August 29, 2014 (#1845) | Morning Dew

Leave a comment