Why is the destructor not making his job?

  • Thread starter Thread starter manuelalonge
  • Start date Start date
M

manuelalonge

Guest
Hi All,

I have written the very basic program below, I am new to C#. The destructor ~Program() doesn't get called, so I do not see in the output the 'Destructor called' string. I have checked other similar questions but I don't find the answer to mine. Thanks.


using System;
using
System.Collections.Generic;
using
System.Linq;
using
System.Text;
using
static System.Console;

namespace
LyfeCicleObject
{
class Program
{
public Program()
{
WriteLine("Cons called");
}

~
Program()
{
WriteLine("Destructor called");
}

static void Main(string[] args)
{
WriteLine("Main started");

Program p1 = new Program();
{
WriteLine("Block started");
Program p2 = new Program();
WriteLine("Block ended");
}

WriteLine("Main ended");
}

}


Continue reading...
 
Back
Top