Destructor | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Destructor

I am looking at C# tutorial, module 6, section 45, "Destructor". Somehow, my output only have constructor, it doesn't have destructor. And the result is different from the tutorial. I don't know what did I do wrong. (I am using the free version of visual studio 2017 for this code.) class Program { class dog { public dog() { Console.WriteLine("Constructor"); } ~dog() { Console.WriteLine("Destructor"); } } static void Main(string[] args) { dog d = new dog(); Console.ReadKey(); } result: Constructor

15th Jul 2018, 5:19 AM
Kevin Xia
Kevin Xia - avatar
1 Answer
0
Hey, try to remove the Console.ReadKey(); I've tried it, and the result is : Constructor Destructor
24th Oct 2018, 10:02 AM
Pujel
Pujel - avatar