Constructor are never called explicitly ?
help me plz.......
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Jignesh TrivediPosted Sep 15, 2014, 11:57 PM
If you didn't define a constructor in your class, it will be automatically supplied with the default constructor. But if you defined a constructor with parameters, the supplied default constructor will be removed and you won't be able to use it until you explicitly define it in your class.
you can call base class constructor explicitly using this and base keyword in child class constructor only...
public Test(int data)
: base()
{
}
hope this will help you.
VulpesPosted Sep 15, 2014, 3:50 PM
Instead, instance constructors are called in conjunction with the 'new' operator which creates a new instance of the type in question.
If a class or struct has a static constructor, it is called by the runtime once and once only before any instances are created or any static members are referenced.
Within a class an instance constructor can call its base class constructor using the 'base' keyword.
Within a class or struct, it is also possible for one instance constructor to call another using the 'this' keyword. This is known as constructor chaining.