创建了析构方法,无法执行怎么回事?

来源:百度知道 编辑:UC知道 时间:2024/07/02 06:35:25
class ME
{
public ME()
{
Console.WriteLine("创建基类");
}
~ME()
{
Console.WriteLine("基类销毁");
}
}
class MySon:ME
{
public MySon()
{
Console.WriteLine("创建子类");
}
~MySon()
{
Console.WriteLine("子类销毁");
}
}
class Program
{
public static void Main(string[] args)
{
MySon ms= new MySon();
Console.ReadLine();
}
}

首先析构方法不是你自己调用的而是系统自动调用的

我试了下你的程序可以调用,
你是不是到了Console.ReadLine(); 没发现析构就说不行了?
这时候还没有达到系统析构的要求
等你过了Cosnole.ReadLine()他才会析构

总结来说,等你程序停了你按下回车就看到了