如何解决基本类型的方法分辨率
| 我的情况是这样的:public class InheritedClass : BaseClass
{
public override void SomeMethod()
{
AnotherMethod();
}
public override void AnotherMethod()
{
}
}
public class BaseClass
{
public virtual void SomeMethod()
{ }
public virtual void AnotherMethod()
{ }
}
那么,当我调用InheritedClassInstance.SomeMethod
时会调用哪种方法?它叫InheritedClassInstance.AnotherMethod
还是BaseClass的AnotherMethod
?
解决方法
叫
InheritedClassInstance.AnotherMethod()
如果您希望它调用基类AnotherMethod()
,则应编写base.AnotherMethod()
,除非您显式调用基本方法(base.AnotherMethod()
),否则它将在继承的类上调用派生方法。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。