How u call destructor and dispose methode in c#.NET
Answer Posted / 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 View All Answers
What is the difference between dynamic and var in c#?
What is system console writeline in c#?
Why do we need events in c#?
What is the use of delegates in c#?
Can we inherit private class in c#?
What happens during the process of boxing?
What is an escape sequence?
What is using keyword in C#?
What is a function c#?
Can a struct have a default constructor (a constructor without parameters) or a destructor in c#?
What is encapsulation in csharp?
What is the lock statement in c#?
What is an array? Give the syntax for a single and multi-dimensional array?
What is difference between web and window application?
what will be the output of the given below coding. using System; public class Exercise { static void OddNumbers(int a) { if (a >= 1) { Console.Write("{0}, ", a); a -= 2; OddNumbers(a); } } public static int Main() { const int Number = 9; Console.WriteLine("Odd Numbers"); OddNumbers(Number); Console.WriteLine(); return 0; } }