force the GC to invoke Finalize() for finalizable objects created in this AppDomain. : Destructor « Class Interface « C# / C Sharp






force the GC to invoke Finalize() for finalizable objects created in this AppDomain.

 

using System;
using System.Collections.Generic;
using System.Text;

public class MyResourceWrapper {
    ~MyResourceWrapper() {
        Console.Beep();
    }
}
class Program {
    static void Main(string[] args) {
        MyResourceWrapper rw = new MyResourceWrapper();
    }
}

 








Related examples in the same category

1.Finalizable Disposable Class
2.the destructors are called bottom-up, which confirms the sequencing of destructors.
3.Shows that stack unwinding in C# does not necessarily call destructorsShows that stack unwinding in C# does not necessarily call destructors
4.Illustrates a destructorIllustrates a destructor
5.Demonstrate a destructorDemonstrate a destructor