This code:
var myClass = new TestConstructor() { MyInt = 50 };
effectively transforms into:
var tmp = new TestConstructor();
tmp.MyInt = 50;
var myClass = tmp;
How would you expect a property to be set before the constructor runs?
(Using a temporary variable here is not important in this case, but it may be in other cases:
var myClass = new TestConstructor { MyInt = 50 };
myClass = new TestConstructor { MyInt = myClass.MyInt + 2 };
In the second line, it is important that myClass.MyIntyou still refer to the first object, not the newly created one.)
source
share