コード例 #1
0
        public void Test3()
        {
            var handle = new MyHandle(new IntPtr(16));

            using (handle)
            {
                // Do something
            }
            // Sanity check
            Debug.Assert(handle.Handle == IntPtr.Zero);
        }
コード例 #2
0
        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);
        }
コード例 #3
0
        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);
        }