Meaning of () => Operator in C#, if it exists

前端 未结 5 1088
余生分开走
余生分开走 2020-12-07 22:30

I read this interesting line here, in an answer by Jon Skeet.

The interesting line is this, where he advocated using a delegate:

Log.Info(\"I did som         


        
5条回答
  •  臣服心动
    2020-12-07 23:18

    This introduces a lambda function (anonymous delegate) with no parameters, it's equivalent to and basically short-hand for:

    delegate void () { return action.GenerateDescription(); }
    

    You can also add parameters, so:

    (a, b) => a + b
    

    This is roughly equivalent to:

    delegate int (int a, int b) { return a + b; }
    

提交回复
热议问题