the following code is from MSDN: Idisposable pattern
protected virtual void Dispose(bool disposing)
{
// If you need thread safety, use a lock around these
// operations, as well as in your methods that use the resource.
if (!_disposed)
{
if (disposing) {
if (_resource != null)
_resource.Dispose();
Console.WriteLine("Object disposed.");
}
// Indicate that the instance has been disposed.
_resource = null;
_disposed = true;
}
}
why the following statement:
_resource = null;
_disposed = true;
are not enclosed by if (disposing) statement block?
for me i would probably write like this:
if (disposing) {
if (_resource != null) {
_resource.Dispose();
_resource = null;
_disposed = true;
}
Console.WriteLine("Object disposed.");
}
anything wrong with my version?