No. In C # you create an instance of a class, then the runtime calls its constructor. By the time the constructor runs too late to select a different type.
However, a constructor of a derived class always calls one of its base class constructors, and you can use it to your advantage (to avoid code repeating).
, , . , Parent, Child1:Parent Child2:Parent, factory :
public class ParentFactory {
public Parent CreateParent(string type) {
switch(type) {
case "Child1":
return new Child1();
case "Child2":
return new Child2();
default:
throw new ArgumentException("Unexpected type");
}
}
}