首页 > 其他 > 详细

常用代码片段

时间:2015-08-19 01:54:02      阅读:181      评论:0      收藏:0      [点我收藏+]

实现IDisposable的代码片段

 1        ~DemoType()
 2         {
 3             this.Dispose();
 4         }
 5 
 6         #region IDisposable Members
 7 
 8         /// <summary>
 9         /// Internal variable which checks if Dispose has already been called
10         /// </summary>
11         protected Boolean disposed;
12 
13         /// <summary>
14         /// Releases unmanaged and - optionally - managed resources
15         /// </summary>
16         /// <param name="disposing"><c>true</c> to release both managed and unmanaged resources; <c>false</c> to release only unmanaged resources.</param>
17         protected void Dispose(Boolean disposing)
18         {
19             if (disposed)
20             {
21                 return;
22             }
23 
24             if (disposing)
25             {
26                 //TODO: Managed cleanup code here, while managed refs still valid
27             }
28             //TODO: Unmanaged cleanup code here
29 
30             disposed = true;
31         }
32 
33         /// <summary>
34         /// Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
35         /// </summary>
36         public void Dispose()
37         {
38             // Call the private Dispose(bool) helper and indicate
39             // that we are explicitly disposing
40             this.Dispose(true);
41 
42             // Tell the garbage collector that the object doesn‘t require any
43             // cleanup when collected since Dispose was called explicitly.
44             GC.SuppressFinalize(this);
45         }
46 
47         #endregion

 

常用代码片段

原文:http://www.cnblogs.com/bitzhuwei/p/useful-code-snippets.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!