If you declare an inheritance hierarchy where the parent and child classes have a static method with 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 method hiding? None of the methods are involved in the inheritance hierarchy and can only be called using the class name:
BaseClass.DoSomething(); SubClass.DoSomething();
or, unskilled in the class itself. In any case, there is no ambiguity as to which method is being called (ie, "Hide").
* Interestingly, the methods may differ in return type and still generate the same warning. However, if the types of method parameters differ, a warning is not generated.
Note that I'm not trying to create an argument or discuss static inheritance or any other such stupid thing.
source share