class="brush: c-sharp;html-script: false;quick-code: true;smart-tabs: true;auto-links: false;toolbar: false;gutter; true;light: false;ruler: false;pad-line-numbers: 2;collapse: false;tab-size: 4;first-line: 1;"> public class MyClass : IDisposable { public int a; public MyClass() { //构造 } public void Dispose() { Dispose(true); GC.SuppressFinalize(this); } ~MyClass() { Dispose(false); } protected virtual void Dispose(bool disposing) { if (disposing) { //析构 //执行基本的清理代码 } } }