// Override System.Object.Finalize() via finalizer syntax.
class MyResourceWrapper
{
~MyResourceWrapper()
{
// Clean up unmanaged resources here.
// Beep when destroyed (testing purposes only!)
Console.Beep();
}
}
If you were to examine this C# destructor using ildasm.exe, you will see that the compiler
inserts some necessary error checking code. First, the code statements within the scope of your
Finalize() method are placed within a try block (see Chapter 7). The related finally block ensures
that your base classes’ Finalize() method will always execute, regardless of any exceptions
encountered within the try scope:
.method family hidebysig virtual instance void
Finalize() cil managed
{
Do'stlaringiz bilan baham: |