+ 1
I don't understand why my destructor is not working. Can anybody explain why ?
namespace Tes{ Class program { class Dog { public Dog() { Console.WriteLine("constructor"); } ~Dog() { Console.WriteLine("Destructor."); } } static void Main(string[] args) { Dog D= new Dog(); } } }
2 Réponses
+ 2
Me neither
https://code.sololearn.com/ciHFz1vNThhY
I copied you code in to the playground and here it does work.
The only difference is that the sololearn server does finish the entire program and your program may not.
In C# memory is mamaged by the garbage collector
The destructor may not be called, or you won't be able to see the result that are shown when the program closes.
You could try
D = null;
GC.Collect;
To force the garbage collector to clean up the dog object
Please put the language you use in the tags.
+ 1
Got it Thank You..!!