HelloSnoopy
在 using 语句中创建一个实例,确保退出 using 语句时在对象上调用 Dispose。当到达 using 语句的末尾,或者如果在语句结束之前引发异常并且控制离开语句块,都可以退出 using 语句。
实例化的对象必须实现 System.IDisposable 接口。
using System.Drawing;
class a
{
   
public static void Main()
   
{
      
using (Font MyFont = new Font("Arial"10.0f), MyFont2 = new Font("Arial"10.0f))
      
{
         
// use MyFont and MyFont2
      }
   // compiler will call Dispose on MyFont and MyFont2

      Font MyFont3 
= new Font("Arial"10.0f);
      
using (MyFont3)
      
{
         
// use MyFont3
      }
   // compiler will call Dispose on MyFont3

   }

}

分类:

技术点:

相关文章:

  • 2021-12-30
  • 2022-12-23
  • 2021-06-02
  • 2021-09-10
  • 2021-12-04
  • 2021-11-10
  • 2021-04-06
  • 2022-02-12
猜你喜欢
  • 2021-11-18
  • 2022-12-23
  • 2021-12-20
  • 2022-03-04
  • 2021-07-30
  • 2021-10-02
  • 2021-10-31
相关资源
相似解决方案