C #-Class _ destructor

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.