Can I ignore delegate parameters with lambda syntax?

前端 未结 7 1700
野的像风
野的像风 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:54

    As others said, no, you can't skip declaring the parameters to a lambda. But, for cleanliness, I suggest giving them a name such as _. For example

    foo.Click += (_,__) => { ... }
    

    You aren't ignoring them per-se, but you're indicating you don't care what they are and will not use them.

提交回复
热议问题