は、次のクラスを考えてみましょうコード(bar = null
とします)。使用のデフォルトのプロパティ値
コンストラクタの初期化子がデフォルトのプロパティ値を使用するようにしてください(例:bar
がnull
の場合)。
if (bar == null) {
foo = new Foo();
} else {
foo = new Foo { Bar = bar };
}
それとも
がfoo = new Foo();
if (bar != null)
foo.Bar = bar;
はちょうどその値を代入しませんか? 'if(bar!= null){...}' –
@ LasseV.Karlsen条件文は、パラメータの数が増えると複雑になります。 – danrah
[オブジェクトイニシャライザと動的にプロパティを指定する]の重複している可能性があります(http://stackoverflow.com/questions/2234091/object-initializer-and-dynamically-specifying-properties) – slawekwin