8.24.2012

Difference between Constructor and Destructor in C#

Difference between Constructor and Destructor in C#
S.No Constructor Destructor
1
It is a special type of method which will be executed automatically while creating an object
It will be executed automatically while destroying object

2
Constructor name must be same as class name with out return type

The name of destructor must be same as class name with a ~(tilde) prefix and with out return type and with out access specifiers
3
Syntax:
public class_name()
{
}
Syntax:
~class_name()
{
}
4
These are overloadable
These are not overloadable
5
These are used to initialize the variables to open files or database connection etc
It is used to de-allocate the memory

No comments:

Post a Comment