How to call a base constructor in C#?
How to call a base constructor in C#?
I completed my post-graduation in 2013 in the engineering field. Engineering is the application of science and math to solve problems. Engineers figure out how things work and find practical uses for scientific discoveries. Scientists and inventors often get the credit for innovations that advance the human condition, but it is engineers who are instrumental in making those innovations available to the world. I love pet animals such as dogs, cats, etc.
Aryan Kumar
13-Jul-2023To call a base constructor in C#, you can use the
base()keyword. Thebase()keyword takes the parameters of the base constructor as a parameter.For example, the following code calls the
BaseClass()constructor from theDerivedClass()constructor:C#
When the
DerivedClass()constructor is called, thebase()keyword calls theBaseClass()constructor first. Then, theDerivedClass()constructor does other things.Here is an explanation of the code:
base()keyword is used to call theBaseClass()constructor.BaseClass()constructor is the base class constructor for theDerivedClassclass.DerivedClass()constructor takes no parameters.DerivedClass()constructor calls thebase()keyword to call theBaseClass()constructor.DerivedClass()constructor also does other things.