C#中using语句的大多数示例都在括号内声明对象,如下所示:
using (SqlCommand cmd = new SqlCommand("SELECT * FROM Customers", connection))
{
// Code goes here
}
Run Code Online (Sandbox Code Playgroud)
如果我使用using语句以下方式使用using语句之外的对象会发生什么:
SqlCommand cmd = new SqlCommand("SELECT * FROM Customers", connection);
using (cmd)
{
// Code goes here
}
Run Code Online (Sandbox Code Playgroud)
以第二个例子中的方式使用using语句是一个坏主意,为什么?
FileStream.Read 方法的第二个参数称为 offset,但它是像索引一样从零开始还是从 1 开始?