使用陈述题 [英] Using statement question
问题描述
我有两个问题.
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?
谢谢!
推荐答案
-
当对象实现
IDisposable
时,应始终使用using
语句.这包括连接.
You should always use a
using
statement when an object implementsIDisposable
. This includes connections.
它将创建两个嵌套的 try {} finally {}
块.
It will create two nested try{}finally{}
blocks.
这篇关于使用陈述题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!