Expression Lambda versus Statement Lambda

前端 未结 8 853
北荒
北荒 2020-12-30 02:02

Fundamentally, is there any difference between a single-line expression lambda and a statement lambda? Take the following code, for example:

private delegate         


        
8条回答
  •  别那么骄傲
    2020-12-30 02:20

    Reflector to the rescue! The disassembled code looks like this:

    private static void Main(string[] args)
    {
        MyDelegate myDelegate1 = delegate {
            Console.WriteLine("Test 1");
        };
        MyDelegate myDelegate2 = delegate {
            Console.WriteLine("Test 2");
        };
        myDelegate1();
        myDelegate2();
        Console.ReadKey();
    }
    

    So no, there is no real difference between the two. Be happy.

提交回复
热议问题