更新时间:2022-04-26 07:53:04
这已经由Eric和Jon在答案的这个问题。长话短说 - 这是C#编译器是如何工作的;准确地说,与方法组转换处理决定什么样的委托,将被转换为使用重载决议,其中时,不采取帐户返回类型
This has already been explained by Eric and Jon in answers to this question. Long story short - this is how C# compiler works; precisely, when dealing with method group conversion deciding what delegate it will be converted to utilizes overload resolution, which does not take return types in account:
这里的原则是确定方法组可兑换需要使用重载的方法组中选择的方法和重载不考虑返回类型。
The principle here is that determining method group convertibility requires selecting a method from a method group using overload resolution, and overload resolution does not consider return types.
在您的例子编译器看到两个动作< T>
和 Func键< T,T>
为***匹配的为添加
。这就增加了两种可能的选择,而且由于它需要一个 - 发出适当的错误
In your example compiler sees both Action<T>
and Func<T, T>
as best match for Add
. This adds up to two possible choices, and since it requires one - appropriate error is issued.