问题描述
我刚刚看过下面的代码,但是我不理解构造函数声明中基类的派生。这是什么?使用序数方法可以吗?
I have just seen following code but I do not understand the derivation of base class right in the constructor declaration. What is this and is this possible with ordinal methods?
public SplashAppContext(Form mainForm, Form splashForm) : base(splashForm)
{
this.mainForm = mainForm;
splashTimer.Tick += new EventHandler(SplashTimeUp);
splashTimer.Interval = 2000;
splashTimer.Enabled = true;
}
推荐答案
它正在调用基类构造函数,将类型为 Form
的参数 splashForm
传递给它。
It's calling a base class constructor, passing the argument splashForm
of the type Form
to it.
您也可以调用基类方法。例如,如果您重写了要稍微修改其行为的方法,则进行修改并使用 base.TheMethod()
调用基类方法。看起来像这样:
You can call base class methods as well. If you for example have overridden a method which behaviour you want to modify slightly, you do your modifications and call the base class method with base.TheMethod()
. This would look like this:
public override void FireMissiles()
{
PrimeMissiles();
base.FireMissiles();
}
调用基类构造函数和基类方法的语法因您而异可以看到。
The syntax for calling a base class constructor and a base class method differs as you can see.
这篇关于在构造函数中使用继承(publix X():y)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!