For example
Protected override void Finalize()
{
try
{
Console.WriteLine(“Destructing Object….”);
//put some code here.
}
finally
{
base.Finalize();
}
}
Destructor
<!--[if !supportLists]--> A
destructor is just opposite to constructor.<!--[endif]-->
<!--[if !supportLists]--> It
has same as the class name, but with prefix ~ (tilde).<!--[endif]-->
<!--[if !supportLists]--> They
do not have return types, not even void and therefore they cannot return
values.<!--[endif]-->
<!--[if !supportLists]-->
destructor is invoked whenever an object is about to be garbage
collected<!--[endif]-->
Eg:
class person
{
//constructor
person()
{
}
//destructor
~person()
{
//put resource freeing code here.
}
}
No comments:
Post a Comment