Overload resolution on operator == with variant generic delegate types

房东的猫 提交于 2019-12-05 09:53:09

Question: But why does the fourth WriteLine lead to the (object, object) overload being used?

Because it's the only choice for the compiler :-)

Cannot apply operator '==' to operands of type 'System.Func<System.ICloneable>' and 'System.Func<System.IConvertable>'

candidates are:

bool==(System.Delegate, System.Delegate) 
bool==(System.Func<System.ICloneable>, System.Func<System.ICloneable>)
bool==(System.Func<System.IConvertable>, System.Func<System.IConvertable>)

so using your (object, object) is the best choice the compiler finds.

same for the Actions

Cannot apply operator '==' to operands of type 'System.Action<string>' and 'System.Action<System.Uri>'

candidates are:

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