使用陈述题 [英] Using statement question

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

问题描述

我有两个问题.

1)是否应该始终在连接上使用using语句?那么,我会在连接上使用它,然后在连接内的阅读器上使用它吗?因此,我将使用两个using语句.

1) Should you always use a using statement on a connection? So, I would use it on the connection and then another one on a reader within the connection? So I would be using two using statements.

2)假设您在连接上使用了using语句,并且在连接上还返回了阅读器.因此,您有两个using语句.它会创建两个Try {} Finally {}块还是一个?

2) Lets say you use the using statement on the connection and also a reader being returned on the connection. So you have two using statements. Does it create two Try{}Finally{} blocks or just one?

谢谢!

推荐答案

  1. 当对象实现 IDisposable 时,应始终使用 using 语句.这包括连接.

  1. You should always use a using statement when an object implements IDisposable. This includes connections.

它将创建两个嵌套的 try {} finally {} 块.

It will create two nested try{}finally{} blocks.

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

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