If you declare an inheritance hierarchy where both the parent and child class have a static method of the same name and parameters*, Visual Studio will raise warning CS0108:
Example:
public class BaseClass
{
public static void DoSomething()
{
}
}
public class SubClass : BaseClass
{
public static void DoSomething()
{
}
}
: warning CS0108: 'SubClass.DoSomething()' hides inherited member 'BaseClass.DoSomething()'. Use the new keyword if hiding was intended.
Why is this considered method hiding? Neither method is involved in the inheritance hierarchy and can only be invoked by using the class name:
BaseClass.DoSomething();
SubClass.DoSomething();
or, unqualified in the class itself. In either case, there is no ambiguity as to which method is being called (i.e., no ‘hiding’).
*Interestingly enough, the methods can differ by return type and still generate the same warning. However, if the method parameter types differ, the warning is not generated.
Please note that I am not trying to create an argument for or discuss static inheritance or any other such nonsense.
Members of the SubClass will not be able to access the DoSomething from BaseClass without explicitly indicating the class name. So it is effectively “hidden” to members of SubClass, but still accessible.
For example: