I have to many class properties and making another constructor just for one field is more harder then something like Inheritance.
For example i have class with one main costructor and one constructor with one parameter
public class mySampleClass
{
//properties
public string Default{get;set;}
public mySampleClass()
{
// fill all properties with default values
Default = "First";
}
public mySampleClass(string value)
{
// i want here to use default constructor and just manipulate some property with 'value'
value = Default; // value = First
}
}
Is it possible 2nd constructor to inherit all default properties from first constructor and just manipulate some data from additional value, or i must again build all default values for 2nd constructor?
It’s not clear what you mean by “inherit all default properties” but you can make the second constructor call the first like this:
Normally, however, you do things the other way round: make constructors with fewer parameters call constructors with more parameters, leaving only the most specific constructor doing any work:
That generally avoids setting a default value in the parameterless constructor and then overwriting it in another one.