Новый курс! Каждый программист должен знать генеративный ИИ!
Попробуйте бесплатный урок0
Can we destroy an instantiated object manually and call its destructor before we exit the scope which it was declared? (C#)
In the course they showed a piece of code like this: Dog d = new Dog(); and it would output this: "Animal created. Dog created. Dog destroyed. Animal destroyed." I tried doing this: d = null; GC.Collect(); Console.WriteLine("Dog"); But the Dog and Animal destructors are always called last when program ends, is there a way to call them manually? I hope I explained well.
2 ответов
+ 1
Override the Finalize().
https://msdn.microsoft.com/en-us/library/system.object(v=vs.110).aspx
0
Thx!