public void Test1() { var handle = new MyHandle(new IntPtr(16)); try { // do something } finally { 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); }