Extension methods with generics

邮差的信 提交于 2019-12-01 09:43:18

Okay, the problem is that in the overload resolution process, the compiler finds all applicable candidate methods without checking the generic constraints specified in the method, picks the most specific one, and then checks the generic constraints.

In this case, the generic method is more specific than the non-generic one (as after type parameter substitution, it's effectively a method with an IChildA parameter instead of an IBase parameter) - but it then fails the constraints.

I have a blog post explaining this in more detail, and another one using it in a horrible way.

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