Constructor
what is constructor & deconstructor with example??
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.
VulpesPosted Aug 11, 2012, 7:05 PM
There are two types: instance and static. The former applies to a specific instance and the latter to the class or struct as a whole. Static constructors cannot be called directly but are called by the system before any instance constructor executes.
A destructor is a special method (sometimes referred to as a finalizer) which provides finalization code for a class instance before the garbage collector destroys it. It cannot be called directly but is called by the system just before the instance is about to be destroyed and its memory reclaimed.
Here's a simple example of all three of these constructs:
The output (the third line only shows after pressing a key) is:
Akkiraju IvaturiPosted Aug 11, 2012, 4:22 PM