In C# the new
modifier can be used to hide a base class method without overriding the base class method.
I\'ve never encountered a situation where hidin
There are rare, but very good, reasons to use method hiding. Eric Lippert posted a great example on his blog:
interface IEnumerable<T> : IEnumerable {
new IEnumerator<T> GetEnumerator();
}
However, I think hiding should be the exception, and only used sparingly.
The most common example I can think of here is things like DbCommand
vs SqlCommand
; the concrete types (SqlCommand
etc) generally do a lot of method hiding to make the return types of properties / methods display the correct implementation type. This is because the related objects themselves have additional (implementation-specific) features, and the caller doesn't want to have to cast every time they call do anything.