IDisposable最佳实现模式

/// <summary> /// 实现了IDisposable接口的类。 /// </summary> public class ConnectionManager : IDisposable {     #region IDisposable模式      /// <summary>     /// 析构函数。     /// </summary>     ~ConnectionManager()     {         Dispose(false);     }      /// <summary>     /// 真正的释放资源函数。     /// </summary>     /// <param name="disposing"></param>     protected virtual void Dispose(bool disposing)     {         if (disposing)         {             // Clean up all managed resources that is finalizable             // ...         }         // Clean up all native resources         // ...     }      /// <summary>     /// 提供使用者一个显式释放资源的方法。     /// </summary>     public void Dispose()     {         Dispose(true);         // Tell the GC not to execute the deconstructor any more         GC.SuppressFinalize(this);     } }
原文地址:https://www.cnblogs.com/shihao/p/2231976.html