namespace ConsoleApplication2
{
class Program
{
class A
{
int x, y;
public A(int a, int b) { x = a; y = b; }
public int add() { return x + y; }
public int sub() { return x - y; }
~A()
{
Console.WriteLine("Detroyed");
}
}
static void Main(string[] args)
{
A ob = new A(9, 4);
Console.WriteLine(ob.add());
Console.WriteLine(ob.sub());
ob = null;
System.GC.Collect();
Console.WriteLine("End");
Console.Read();
}
}
}
正在运行的输出
11
5
End
Destroyed
但在调试模式下,它会提供此输出
11
5
Destroyed
End