Can I ignore delegate parameters with lambda syntax?

前端 未结 7 1722
野的像风
野的像风 2020-12-08 10:09

I am curious why C# allows me to ignore delegate parameters in some cases but not others.

For instance this is permitted:

Action action =          


        
7条回答
  •  不思量自难忘°
    2020-12-08 10:31

    The () => ... syntax explicitly specifies that the lambda takes no parameters. Perhaps the language could be modified so that () => really meant "Infer the parameters of this lambda for me" in the same way the delegate syntax does, but that would make the language more complicated. When designing new language features, you start at minus 100, and I don't think this one passes the test.

    There may also be more technical reasons why this would be difficult to implement (which is probably more in line with what you were asking for, but I doubt the technical reasons drove this decision if it ever came up).

提交回复
热议问题