If you make an inherited class in C# (VS2005) do you need to explicitly call the constructor of the higher class, or will it be called automatically?
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
The default (parameterless) constructor will automatically be invoked if not supplied.
In other words, these are equivalent:
and
assuming that Foo’s base has a parameterless constructor.
On the other hand, if the base only has a constructor with parameters like this:
then
will not compile. In this case you must explicitly call the base with the appropriate parameter – e.g.