覆盖(或阴影)与扩展方法的方法? [英] Override (or shadow) a method with extension method?

查看:107
本文介绍了覆盖(或阴影)与扩展方法的方法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

可能重复:
  <一href="http://stackoverflow.com/questions/899539/is-there-any-way-in-c-sharp-to-override-a-class-method-with-an-extension-method">Is有没有办法在C#与扩展方法重载一个类的方法?

是否有可能覆盖或的shadow (的在C#中新)实例方法与扩展方法?

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

推荐答案

没有。从 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.

这篇关于覆盖(或阴影)与扩展方法的方法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆