using System;
public class MyClass
{
private int[] data;
public MyClass(int size)
data = new int[size];
Console.WriteLine("MyClass instance created");
}
~MyClass()
Console.WriteLine("Destructor (finalizer) called for MyClass");
public class MainClass
public static void Main(string[] args)
// Create an instance of MyClass
MyClass myObj = new MyClass(1000000);
// Let's pretend we do something with myObj
// The destructor (~MyClass) will be automatically called when myObj is no longer in use
// It's not necessary to explicitly call the destructor in C#
// Force garbage collection to demonstrate the finalizer being called
GC.Collect();
GC.WaitForPendingFinalizers();