【发布时间】:2018-12-01 18:37:18
【问题描述】:
我想重写一个方法,但我仍然希望在我重写时调用父方法。当我尝试使用 :base() 调用父方法时,它会显示 unexpected token。
public class A
{
public virtual void DoStuff()
{
//some code
}
}
public class B : A
{
public override void DoStuff() : base()
{
//some other code
}
}
在java中我会是:
super.DoStuff()
【问题讨论】:
-
不,你不能那样做。您需要从派生方法中手动调用
base.DoStuff()。
标签: c# overriding