Thursday, April 19, 2012

Difference between constructor and destructor in c#

Constructor:
*It is a special type of method  which will be executed automatically while crating an object
*Constructor name must be same as class name with out return type
syntax:
public class_name()
{
}
*These are overlodabale
*These are used to initialize the variables to open files or database connection etc
Destructor:
*It will be executed automatically while destroying object
*The name of destructor  must be same as class name with a ~(tild) prefix and with out return type and  with out access specifiers
syntax:
~class_name()
{
}
*These are not over lodable
*It is used to de-allocate the memory

1 comment:

Anonymous said...

constructor does not have any return type not even void that means it does not return any value.

Bel