c# - 在构造函数中使用继承 (publix X () : y)

标签 c# derived-class

我刚看到下面的代码,但我不明白构造函数声明中基类的派生。这是什么,使用序数方法可能吗?

public SplashAppContext(Form mainForm, Form splashForm) : base(splashForm)
{
this.mainForm = mainForm;
splashTimer.Tick += new EventHandler(SplashTimeUp);
splashTimer.Interval = 2000;
splashTimer.Enabled = true;
}

最佳答案

它正在调用基类构造函数,将 Form 类型的参数 splashForm 传递给它。

您也可以调用基类方法。例如,如果您覆盖了一个您想要稍微修改其行为的方法,您可以进行修改并使用 base.TheMethod() 调用基类方法。这看起来像这样:

public override void FireMissiles()
{
   PrimeMissiles();

   base.FireMissiles();
}

如您所见,调用基类构造函数和基类方法的语法有所不同。

关于c# - 在构造函数中使用继承 (publix X () : y),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3072249/

相关文章:

c++ - 引用基类的成员 var 导致访问冲突

c# - MonoDroid 值得付出努力吗?

c# - 扩展 Entity Framework 模型以包含新属性

c# - 为什么在将数据源传递给 BindingSource 之前对其调用 .OrderBy 时,我的数据源的类型似乎发生了变化?

c# - 屏蔽时我可以使用哪些逻辑运算来忽略不相关的位?

c# - 来自 Google 网站构建器页面的引荐来源网址被剥离了吗?

haskell - 使用量化约束导出 Ord (forall a. Ord a => Ord (f a))

c# - XML 序列化 : The type of the argument object 'Sw' is not primitive

c++ - 我可以在基类中调用派生类的函数吗?

c++ - 模板部分特化防止从派生类初始化