Answers for "c# trigger destructor"

C#
0

c# trigger destructor

//You don't call the destructor in .NET The managed heap is handled by the CLR and the CLR only.

//You can however define a destructor to a class, the destructor would be called once the object gets collected by the GC

class Foo
    {
        public Foo()
        {
            Console.WriteLine("Constructed");
        }

        ~Foo()
        {
            Console.WriteLine("Destructed");
        }
    }
//Take notice that the destructor doesn't (and can't) have a public modifier in-front of it, it's sort of an hint that you can't explicitly call the destructor of an object.
Posted by: Guest on June-16-2020

C# Answers by Framework

Browse Popular Code Answers by Language