在聊天的讨论过程中,我编写了这个控制台应用程序.
using System;
class Program
{
static void Main(string[] args)
{
CreateClass();
Console.Write("Collecting... ");
GC.Collect();
Console.WriteLine("Done");
}
static void CreateClass()
{
SomeClass c = new SomeClass();
}
}
class SomeClass
{
~SomeClass()
{
throw new Exception();
}
}
Run Code Online (Sandbox Code Playgroud)
Collecting... Done
Unhandled Exception: System.Exception: Exception of type 'System.Exception' was
thrown.
at SomeClass.Finalize()
Run Code Online (Sandbox Code Playgroud)
我本来以为应用程序在 Done打印前会崩溃.
我不太关心如何制作它.我的问题是,为什么不呢?