博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
使用using 语句
阅读量:6950 次
发布时间:2019-06-27

本文共 557 字,大约阅读时间需要 1 分钟。

在 using 语句中创建一个实例,确保退出 using 语句时在对象上调用 Dispose。当到达 using 语句的末尾,或者如果在语句结束之前引发异常并且控制离开语句块,都可以退出 using 语句。

实例化的对象必须实现 System.IDisposable 接口。
示例
// cs_using_statement.cs
// compile with /reference:System.Drawing.dll
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

   }

}

转载地址:http://ihkil.baihongyu.com/

你可能感兴趣的文章
SmartFoxServer 2X 安装
查看>>
Jackson2 json 转换Bean, Bean 里没有对应的值 jackson Un的解决方式
查看>>
Class.isAssignableFrom instanceof 区别
查看>>
win下MySQL 8.0.11 修改密码、开启远程访问
查看>>
媒体查询@media scree
查看>>
andrioid 图像&视频处理
查看>>
MYSQL成绩排名
查看>>
PhpStorm中如何使用Xdebug工具,入门级操作方法
查看>>
Android图片压缩
查看>>
Linux基础培训笔记二
查看>>
使用highcharts绘制图表,如何在tooltip里显示服务器端的其他数据
查看>>
关于C++类回调函数中传进成员变量的方法
查看>>
游戏数据分析指标定义 | 通用
查看>>
第一次想真正的认识自己
查看>>
Oracle Flash Storage System新版手册集
查看>>
ireport 用html页面上 图片怎么都出不来 全是红叉的处理办法
查看>>
activeMQ支持的四种协议简介及性能比较
查看>>
css标签的使用
查看>>
apache+tomcat,搭建负载均衡服务器
查看>>
Andro - Multipurpose OpenCart 2.X 自适应主题模板 ABC-0651
查看>>