Ejemplo n.º 1
0
 /// <summary>
 /// 显示调用 和 自动清理
 /// 顺序如下:
 /// 手动Dispose
 /// using执行的Dispose
 /// 析构函数调用Dispose
 /// </summary>
 public void Test01()
 {
     using (SampleClass c = new SampleClass())
     {
         c.Dispose();
         Console.WriteLine("-----------------");
     }
 }
        /// <summary>
        /// 默认finally释放
        /// </summary>
        public void Test01()
        {
            SampleClass c1 = null;

            try
            {
                c1 = new SampleClass();
            }
            finally
            {
                c1?.Dispose();
            }
        }