Can’t assign delegate an anonymous method with less specific parameter type [duplicate]

寵の児 提交于 2019-12-01 05:36:13

Method group conversions support variance (as of C# 2 - they didn't in C# 1), anonymous function conversions simply don't. Given that whenever you write an anonymous function you can write the appropriate parameter, why not just do so? There would be no benefit in allowing variance there as far as I can see, and it would make the rules harder to get right. (Variance ends up being pretty complex in the spec.)

EDIT: An anonymous method without a parameter list is basically compatible with any delegate's parameter list so long as it doesn't have out parameters. Basically it's a way of saying, "I don't care about the parameters." It's the one feature of anonymous methods that lambda expressions don't have :)

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!