Пример #1
0
        private static void Method2()
        {
            ClassShouldDisposeBase c = null;

            try
            {
                c = new ClassShouldDisposeBase("Method2");
            }
            finally
            {
                c.Dispose();
            }
        }
Пример #2
0
        private static void Method3()
        {
            ClassShouldDisposeBase c = null;

            try
            {
                c = new ClassShouldDisposeBase("Method3");
                Method4();
            }
            catch
            {
                Console.WriteLine("在Method3中捕获了异常。");
            }
            finally
            {
                c.Dispose();
            }
        }
Пример #3
0
        private static void Method4()
        {
            ClassShouldDisposeBase c = null;

            try
            {
                c = new ClassShouldDisposeBase("Method4");
                throw new Exception();
            }
            catch
            {
                Console.WriteLine("在Method4中捕获了异常。");
                throw;
            }
            finally
            {
                c.Dispose();
            }
        }