0
Why the output is: "Constructor Constructor Destructor Destructor"???
namespace ConsoleApplication7 { class Program { static void Main(string[] args) { Test one = new Test(); Test two = new Test(); } } } class Test { public Test() { Console.WriteLine("Constructor"); } ~Test() { Console.WriteLine("Destructor"); } }
2 Respostas
+ 3
one is created. Constructor is called, and "Constructor" is outputted. two us created, and the same thing happens. Then, the destructor is called for both at the end of the program, and "Destructor" is outputted twice. Hope this helps.
+ 1
thanks