0

My child class constructor has the same logic with the Parent class constructor, Is it possible that even my child constructor is omitted but my child class can run parent's constructor automatically?

Example:

public class parent {

   public parent(string id) {
     this.Id = id;
  }
}

public class child : parent
{
   public child(string id):base(id){

   }
}

I do not want the constructor child(string id).

Is there any solution for this?

Joy Zhu
  • 446
  • 4
  • 9
  • 2
    How do you want to construct the child class without any constructor? – asaf92 May 11 '20 at 09:53
  • 3
    related : [Making all derived classes call the base class constructor](https://stackoverflow.com/questions/4296888/c-sharp-making-all-derived-classes-call-the-base-class-constructor) ; "_You do have to redeclare constructors, because they're effectively not inherited. It makes sense if you think of constructors as being a bit like static methods in some respects._" - J. Skeet answers – Drag and Drop May 11 '20 at 09:54
  • try parameterless constructor function – Muhammed Caylak May 11 '20 at 11:33

0 Answers0