LoginSignup
0
0

More than 1 year has passed since last update.

クラスのフィールドをコンストラクト時に配列として初期化する

Posted at

自分メモ。
クラスのフィールドをコンストラクト時に配列化したい場合の書き方。
C#はフィールドの初期化時にフィールドを参照できないが、メソッドとして参照してあげる。

class Hoge {
  ...
  private int value1;
  private int value2;
  private int value3;
  private int value4;
  private int value5;

  private IEnumerator<int> Values()
  {
      yield return this.value1;
      yield return this.value2;
      yield return this.value3;
      yield return this.value4;
      yield return this.value5;
  }
}

0
0
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
0
0