I did not see any explanation of this on MSDN:Object and Collection Initializers. Specifically, I've noted that it is possible to use an object initializer to set a property on a subType, rather than newing the sub-type itself.
The syntax itself doesn't match my understanding of the MSDN page. I understand that I can use an object initializer to set a field of an initialized object, but don't see where it is documented that it is possible to set a field of a field.
It makes sense to me that this is legal. One could accomplish the same thing with bt.subType.subTypeValue=5;
.
class BasicSubType
{
public int subTypeValue;
}
class BasicType
{
public BasicSubType subType {get;private set;}
public BasicType()
{
subType = new BasicSubType();
}
}
void Main()
{
BasicType bt = new BasicType{subType={subTypeValue=5}};
}