0
constructor and destructor
the foll code in the course dhows o/p as "constructor" & "destructor"...but actually when i run the code it shows only constructor. namespace SoloLearn { class Program { class Dog { public Dog() { Console.WriteLine("Constructor"); } ~Dog() { Console.WriteLine("Destructor"); } } static void Main(string[] args) { Dog d = new Dog(); } } } what is the problem
1 Answer
+ 1
The destructor is probably called when the program ends, so it is not printed out.
This is because of the scope : you object exists in the main, but is only destroyed after the main is left. If you create a loop in which you call the object, you should be able to see the destructor.