标签:
我们知道 using 语句只不过是提供能确保正确使用 IDisposable 对象的方便语法。
1: using (IDisposable reader1 = new StreamReader(inputFileName1), 2: reader2 = new StreamReader(inputFileName2), 3: writer = new StreamWriter(outputFileName)) 4: { 5: Merge(reader1 as TextReader, reader2 as TextReader, writer as TextWriter); 6: }
using (R r1 = new R()) {
r1.F();
}
完全等效于
R r1 = new R();
try {
r1.F();
}
finally {
if (r1 != null) ((IDisposable)r1).Dispose();
}
标签:
原文地址:http://www.cnblogs.com/Andy-Li/p/5497456.html