Question: What are peoples preferences between the two methods of creating an object (in C# in particular) and setting other fields (that may not be given values during construction)? Are either of them considered best practice? or is it down to the programmer and any styling conventions in place at the company?
My preference is absolutely for the object initializer method. It looks much cleaner and more concise to me.
Object initializer
Type T = new Type(Param1, Param2)
{
Field1 = Value1,
Field2 = Value2,
Field3 = ValueFromFunction()
};
Constructor
Type T = new Type(Param1, Param2);
T.Field1 = Value1;
T.Field2 = Value2;
T.Field3 = ValueFromFunction();