C# using关键字
这里的using不是指引入程序集的那个using。
是指
using(class t = new class())
{
xxxxxxxxxxxxxxxxxxxxxx
}这里的using的作用是如果这个class实现了IDisposable接口,等价于这样一段:
try{
calss t = new class();
}
finally{
if(t != null){
t.Dispose();
}
}
这里的using不是指引入程序集的那个using。
是指
using(class t = new class())
{
xxxxxxxxxxxxxxxxxxxxxx
}这里的using的作用是如果这个class实现了IDisposable接口,等价于这样一段:
try{
calss t = new class();
}
finally{
if(t != null){
t.Dispose();
}
}