if (_readStream != null)
_readStream.Dispose();
if (_writeStream != null)
_writeStream.Dispose();
}
//这里释放非托管资源
//do something release unmanaged resources.
_disposed = true;
}
}
public void Dispose()
{
this.Dispose(true);
GC.SuppressFinalize(this);
}
}
public class DerivedClass:BaseClass
{
private FileStream _myStream;
//如果该类没有非托管资源则注释该终结器函数,该函数的添加会从一定
//程度上损伤程序性能。
~DerivedClass()
{
this.Dispose(false);
}
public void ReadNextChunk()
{
if (_disposed)
throw new ObjectDisposedException("object has been disposed.");
//do the real thing.
}
protected override void Dispose(bool disposing)
{
if (!_disposed)
{
try
{
i