Calling the base constructor in C#

前端 未结 12 2783
南笙
南笙 2020-11-22 03:04

If I inherit from a base class and want to pass something from the constructor of the inherited class to the constructor of the base class, how do I do that?

For exa

12条回答
  •  萌比男神i
    2020-11-22 03:32

    It is true use the base (something) to call the base class constructor, but in case of overloading use the this keyword

    public ClassName() : this(par1,par2)
    {
    // do not call the constructor it is called in the this.
    // the base key- word is used to call a inherited constructor   
    } 
    
    // Hint used overload as often as needed do not write the same code 2 or more times
    

提交回复
热议问题