protected virtual void Dispose(bool disposing)
{
if (disposing)
{
Stream copyOfStream = this._stream;
this._stream = null;
if (copyOfStream != null && !this._leaveOpen)
{
copyOfStream.Close();
}
}
this._stream = null;
}
在将Stream
设置为this._stream
之前,为什么在上面的代码中创建了null
个实例的副本?
例如为什么不这样:
protected virtual void Dispose(bool disposing)
{
if (disposing)
{
if (this._stream != null && !this._leaveOpen)
{
this._stream.Close();
}
}
this._stream = null;
}