【发布时间】:2011-01-09 08:18:03
【问题描述】:
可能的重复:
Using the using statment in c#
What is the C# Using block and why should I use it?
只是想知道这意味着什么?我在网上看到很多教程都有这样的语法:
using (SqlCeCommand cmd2 = new SqlCeCommand("SELECT city FROM cities JOIN states ON states.id=cities.state WHERE states.state='" + read.GetString(0) + "'", con))
{
SqlCeDataReader readCities = cmd2.ExecuteReader();
while (readCities.Read())
{
parent.Nodes.Add(readCities.GetString(0));
}
}
为什么要使用它?我尝试搜索 Google,但它出现了用于包含 dll 和其他文件的 'using' 关键字。
【问题讨论】:
-
参见 C# 规范的第 8.13 节。
-
你也可以在 SO 上尝试快速搜索,你会发现你创建了一个重复的问题。
-
Zano:这可能对他没有多大帮助,这取决于他是否知道自己在寻找什么。在 C# 中,“using”关键字有两种完全不同的含义。
-
我怀疑大多数开发人员甚至没有意识到 c# 规范的存在。
标签: c# idisposable using using-statement