Does c# supports destructors?

Answer Posted / praveen saxena

Yes and No,
C# supports destructors just to provide a familiar way fo
destructing objects for C++ developers. even syntax also is
same but internally its the dicpose method that does all
the work.

Even if you declare a destructor the compiler automatically
translates a destructor into an override of the
Object.Finalize() method. In other words, the compiler
translates the following destructor:

class Class1
{
~Class1(){}
}

Into the following code:

class Class1
{
Protected override void Finalize()
{
try{..}
finally { base.Finalize();}
}
}

I guess that makes things more clear.

Is This Answer Correct ?    6 Yes 0 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

How main method is called in c#?

517


Why do we use struct in c#?

483


Whats an assembly? Describe the importance of assembly?

495


When should we use delegates in c#?

489


What is monitor in C#?

593






What is dataview c#?

465


What is entity framework c#?

461


What is the difference between Java and .NET garbage collectors?

509


Give an example to show for hiding base class methods?

456


What are c# i/o classes?

569


What is a private class in c#?

495


What is difference between dictionary and list in c#?

455


What are the uses of delegates in c#?

579


How are delegates chosen?

462


What is .cshtml file?

496