What is the difference between lambdas and delegates in the .NET Framework?

后端 未结 17 1413
小蘑菇
小蘑菇 2020-12-12 10:45

I get asked this question a lot and I thought I\'d solicit some input on how to best describe the difference.

17条回答
  •  感动是毒
    2020-12-12 11:13

    lambdas are simply syntactic sugar on a delegate. The compiler ends up converting lambdas into delegates.

    These are the same, I believe:

    Delegate delegate = x => "hi!";
    Delegate delegate = delegate(object x) { return "hi";};
    

提交回复
热议问题