I am having a .Net class which has 10 properties like given below: [the datatypes of individual property is just a placeholder here and it can be anything from a primitive type to an object to a list of objects]
class MyClass
{
internal int Property1{Get;Set;}
internal string Property2{Get;Set;}
internal Myclass2 Property3{Get;Set;}
internal MyAnotherClass Property4{Get;Set;}
internal int Property5{Get;Set;}
internal int Property6{Get;Set;}
internal List<string> Property7{Get;Set;}
internal int Property8{Get;Set;}
internal MyThirdClass Property9{Get;Set;}
internal int Property10{Get;Set;}
}
The purpose of this class is to just hold data and this class will not have any function behavior [similar to POCO classes]. Now I am trying to understand here, as should I create a parameterized constructor in the class and pass it all the values to set these properties or should I use the Collection Initializer to set these properties.
In all cases, all the properties would be set so there is no question of setting selective properties.
If I go ahead with the approach of using constructor then I would create the private members for each of these properties and use them inside the constructor to assign it the respective values. This will avoid calling 10 Setter methods just to create one object of MyClass, but will result in creating a constructor which takes 10 parameters.
Is there a documentation which explains in which case one is advised to use constructor instead of Collection Initializer and Vise a versa? I personally prefer creation of Constructor.
List<int>
instead?