views:

22

answers:

1

Why isnt HashAlgorithm.Dispose public?

void IDisposable.Dispose()
{
    this.Dispose(true);
    GC.SuppressFinalize(this);
}

I understand that it is and explicit interface implementation and can still be called. I am trying to work out what the reasoning is behind it.

+1  A: 

This is called explicit interface implementation. The only way to call this method is to cast to a IDisposable object. One good example of when this might be useful is when you have a class which implements two interfaces that both have the same method name and you want to provide a different implementation for each of them.

Darin Dimitrov
I understand that. Trying to work out what the reasoning is behind it.I have never seen an explicit implementation of IDisposable. Editted question to make clearer.
Simon
While I don't know the reason for explicitly implementing the `IDisposable` interface in the `HashAlgorithm` class I may say that this is a **BAD** practice. Although the using block will work with classes that do have an explicit `IDisposable` implementation, developers who are exploring the object model may not notice that the object has a `Dispose` method and therefore may not take advantage of early cleanup.
Darin Dimitrov