Common Code Snippets

Source: Internet
Author: User

Code snippet to implement IDisposable
1~DemoType ()2         {3              This. Dispose ();4         }5 6         #regionIDisposable Members7 8         /// <summary>9         ///Internal variable which checks if Dispose has already been calledTen         /// </summary> One         protectedBoolean disposed; A  -         /// <summary> -         ///releases unmanaged and-optionally-managed resources the         /// </summary> -         /// <param name= "disposing" ><c>true</c>To release both managed and unmanaged resources;<c>false</c>To release only unmanaged resources.</param> -         protected voidDispose (Boolean disposing) -         { +             if(disposed) -             { +                 return; A             } at  -             if(disposing) -             { -                 //todo:managed Cleanup code here, while Managed refs still valid -             } -             //todo:unmanaged Cleanup Code here in  -disposed =true; to         } +  -         /// <summary> the         ///performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources. *         /// </summary> $          Public voidDispose ()Panax Notoginseng         { -             //Call the private Dispose (bool) helper and indicate the             //That we is explicitly disposing +              This. Dispose (true); A  the             //Tell the garbage collector, the object doesn ' t require any +             //cleanup when collected since Dispose is called explicitly. -Gc. SuppressFinalize ( This); $         } $  -         #endregion

Common Code Snippets

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.