the destructors are called bottom-up, which confirms the sequencing of destructors. : Destructor « Class Interface « C# / C Sharp






the destructors are called bottom-up, which confirms the sequencing of destructors.

 

using System;


public class Starter {
    public static void Main() {
        XClass obj = new XClass();
    }
}

public class MyClass {
    ~MyClass() {
        Console.WriteLine("MyClass destructor");
    }
}

public class YClass : MyClass {
    ~YClass() {
        Console.WriteLine("YClass destructor");
    }
}

public class XClass : YClass {
    ~XClass() {
        Console.WriteLine("XClass destructor");
    }
}

 








Related examples in the same category

1.Finalizable Disposable Class
2.force the GC to invoke Finalize() for finalizable objects created in this AppDomain.
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