基本类型的方法解析 [英] method resolution with base types
本文介绍了基本类型的方法解析的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我的情况是这样:
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
?
So which method is called when I call InheritedClassInstance.SomeMethod
? Does it call InheritedClassInstance.AnotherMethod
, or the BaseClass's AnotherMethod
?
推荐答案
它调用InheritedClassInstance.AnotherMethod()
如果您希望它调用基类AnotherMethod()
,则可以编写base.AnotherMethod()
If you wanted it to call the base class AnotherMethod()
you would write base.AnotherMethod()
这篇关于基本类型的方法解析的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文