c# - 在 C# 中调用基本构造函数

标签 c# asp.net

<分区>

我有以下层次结构:

class Base
{
  public Base(string sMessage)
  {
     //Do stuff
  }
}

class Derived : Base
{
  public Derived(string someParams)
  {

   string sMessage = "Blah " + someParams;

   //Here I want to call the base constructor
   //base(sMessage);

  }

}

最佳答案

您必须在派生类构造函数体之前调用基类构造函数。

class Derived : Base
{
  public Derived(string someParams)
    : base("Blah " + someParams)
  {

  }

}

关于c# - 在 C# 中调用基本构造函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/626765/

相关文章:

c# - 我在哪里使用 mvc4 和 EF 在 asp.net 中散列密码?

asp.net - 如何在谷歌图表中以印度格式格式化金额

c# - assembly.GetTypes() 不返回所有类型

c# - C# 如何生成 GUID?

c# - 使用 Rijndael 算法加密文件

ASP.NET MembershipProvider 加密/解密

asp.net - 如何使用另一个表中的列来引用两个表 - Entity Framework

c# - 泛型阻止虚函数调用?

c# - 以编程方式重置 Windows XP 空闲时间

javascript 专注于验证失败的文本框,在 Chrome 和 Firefox 中工作方式不同