public void Test3() { var handle = new MyHandle(new IntPtr(16)); using (handle) { // Do something } // Sanity check Debug.Assert(handle.Handle == IntPtr.Zero); }
public void Test2() { var handle = new MyHandle(new IntPtr(16)); try { // do something } finally { ((IDisposable)handle).Dispose(); } // Sanity check Debug.Assert(handle.Handle == IntPtr.Zero); }
public void Test4() { var handle = new MyHandle(new IntPtr(16)); { MyHandle invisible = handle; try { // Do something } finally { invisible.Dispose(); // No boxing, due to optimization } } // Sanity check Debug.Assert(handle.Handle == IntPtr.Zero); }