How u call destructor and dispose methode in c#.NET



How u call destructor and dispose methode in c#.NET..

Answer / ruchika mathur

Destructor: They are special methods that contain the
cleanup code for the object.You cannot call them explicitly
as they are called by GC implicitly.
Class MyClass
{
~MyClass()
{
}
}

public interface IDisposable
{
void Dispose();
}
Class Test:IDisposable
{
protected void Dispose()
{
if(disposing)
{
// Code to dispose the managed resources of the class
}
// Code to dispose the un-managed resources of the class

isDisposed = true;
}

public void Dispose()
{
Dispose(true);
GC.SuppressFinalize(this);
}


}
}

Is This Answer Correct ?    2 Yes 2 No

Post New Answer

More C Sharp Interview Questions

What happens if the inherited interfaces have conflicting method names?

0 Answers  


What is access modifier in c#?

0 Answers  


Can we return two values from a function?

12 Answers   MD Synergy,


what is collections in .net? why we use?

0 Answers  


Define boxing and unboxing in c#?

0 Answers  






Can fields inside a class be virtual?

0 Answers  


What is the difference between a variable and a literal?

0 Answers  


What is cookies in c# asp net?

0 Answers  


What are Custom Control and User Control?

1 Answers  


Why do we override in c#?

0 Answers  


Why do we need constructor in c#?

0 Answers  


What is deferred execution in c#?

0 Answers  


Categories