Question

Why isn't HashAlgorithm.Dispose public?

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

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

Was it helpful?

Solution

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top