1 usingSystem;2 usingSystem.Collections.Generic;3 usingSystem.Linq;4 usingSystem.Text;5 6 /*----------------------------------------------------------------------------------------------------------- -7 * Class _ Destructor:8 * 1. Used primarily to dispose of managed and non-9 * Managed resources.Ten * 2. Implicitly invokes the Finalize () method of the object base class One * 3. No reference A * 4. No return value - * 5. You cannot define destructors in structs, only use destructors on classes - * 6. One class can have only one destructor the * 7. Cannot inherit or reload - * 8. Unable to display the call, can only be called automatically by the garbage collection period - ----------------------------------------------------------------------------------------------------------- -*/ - namespaceclass _ destructor + { - class Person + { A PublicPerson () at { - - } -~Person () - { - //You must add a reference: System.Windows.Forms inSystem.Windows.Forms.MessageBox.Show ("destructors have been called!"); - } to /*---------------------------------------------------------------------------------------------- + * ~person () The destructor is implicitly converted to the following code - * ---------------------------------------------------------------------------------------------- the protected override void Finalize () * { $ TryPanax Notoginseng { - Console.WriteLine ("Destructor is called!"); the } + finally A { the base. Finalize (); + } - } $ ----------------------------------------------------------------------------------------------*/ $ - } - the class Program - {Wuyi Static voidMain (string[] args) the { -Person p =NewPerson (); Wu console.readline (); - } About } $ -}
C #-Class _ destructor