我应该为流对象调用Close()还是Dispose()吗?
类如Stream,StreamReader,StreamWriter等工具IDisposable界面。这意味着,我们可以Dispose()对这些类的对象调用方法。他们还定义了public一种称为的方法Close()。现在,让我感到困惑的是,一旦完成对象我该怎么称呼?如果我都叫我怎么办? 我当前的代码是这样的: using (Stream responseStream = response.GetResponseStream()) { using (StreamReader reader = new StreamReader(responseStream)) { using (StreamWriter writer = new StreamWriter(filename)) { int chunkSize = 1024; while (!reader.EndOfStream) { char[] buffer = new char[chunkSize]; int count = reader.Read(buffer, 0, chunkSize); if (count != 0) { writer.Write(buffer, 0, count); } } …