Override (or shadow) a method with extension method? [duplicate]

[亡魂溺海] 提交于 2019-11-28 02:54:21

问题


Possible Duplicate:
Is there any way in C# to override a class method with an extension method?

Is it possible to override or shadow (new in C#) instance methods with extension methods?


回答1:


No. From MSDN:

You can use extension methods to extend a class or interface, but not to override them. An extension method with the same name and signature as an interface or class method will never be called. At compile time, extension methods always have lower priority than instance methods defined in the type itself.



来源:https://stackoverflow.com/questions/1745166/override-or-shadow-a-method-with-extension-method

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