LoginSignup
1
2

More than 5 years have passed since last update.

コンストラクタの継承【C#】

Last updated at Posted at 2018-12-01

サブクラス(継承先)のコンストラクタでスーパークラス(基底クラス)の処理も呼び出したいときの実装方法。

//継承先に引数がないパターン
public SuperClass(int num, string text)
{
  // 処理
}

public SubClass() : base(5, "text")
{
  // 処理
}

//継承先の引数が多いパターン
public SuperClass(int num, string text)
{
  // 処理
}

public SubClass(int num, string text, bool flag) : base(num, text)
{
  // 処理
}
1
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
2