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

Explain how can you clean up objects holding resources from within the code?

566


What is a thread c#?

588


Which is faster list or dictionary in c#?

641


What is property c#?

594


Is php better than c#?

580






What is the difference between finalize() and dispose() methods?

635


What benefit do you get from using a primary interop assembly (pia)?

606


What is anonymous method in c#?

545


What are the problem with .NET generics?

638


What is use of private class in c#?

614


What are the types of constructors?

582


What are the namespace level elements?

581


Could you explain the difference between func vs action vs predicate?

536


What are synchronous and asynchronous operations?

567


What is string interpolation in c#?

623