如果我有以下情况:
StreamWriter MySW = null;
try
{
Stream MyStream = new FileStream("asdf.txt");
MySW = new StreamWriter(MyStream);
MySW.Write("blah");
}
finally
{
if (MySW != null)
{
MySW.Flush();
MySW.Close();
MySW.Dispose();
}
}
MySW.Dispose()
即使提供了关闭,我也可以直接调用并跳过关闭吗?是否有任何不能按预期工作的流实现(如 CryptoStream)?
如果不是,那么以下只是错误的代码:
using (StreamWriter MySW = new StreamWriter(MyStream))
{
MySW.Write("Blah");
}