关于使用块的问题 [英] Question on using block

查看:38
本文介绍了关于使用块的问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


您好,


以下代码是否缺少任何 "使用"阻止或它看起来没问题?请告知。

解决方案

使用块仅适用于实施的类型
IDisposable
 这意味着该类型正在使用或创建一些显式杀死所需的非托管资源,当我们在实例化这些类型时使用block编写时,编译器将其转换为代码为
尝试捕获最终,并确保这些未受管理的资源,例如
SQL Server连接,一个打开的文件被释放。



SO,推荐的方法用于实现 IDisposabl的类型 e接口是在使用时将它们包装在使用块中。




希望它有帮助!


Hello,

Is the following code missing any "using" block or it looks ok?Please advise.

解决方案

Using block is only available for the types which implement IDisposable which means that the type is using or creating some un-managed resources that are needed to explicitly killed, and when we write using block when instantiating those types, the compiler converts that code in to try, catch and finally and makes sure that those un-managed resources like SQL Server Connection, an opened file are released.

SO, recommended approach for types which implement IDisposable interface is to wrap them in using block when consuming.

Hope it helps!


这篇关于关于使用块的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆