This is somewhat related to a question I just asked last week: C# static member “inheritance” - why does this exist at all?.
To cut to the chase, C# doesn't really support static method inheritance - so, you can't do what you ask. Unfortunately, it is possible to write MyOtherClass.MyStaticMethod()
- but that doesn't mean there's any real inheritance going on: under the covers this is just the scoping rules being very lenient.
Edit: Although you can't do this directly, you can do what C++ programmers call a Curiously Recurring Template Pattern and get pretty close with generics[1]:
public class MyClass<TDerived> where TDerived:MyClass<TDerived> {
public static string MyStaticMethod() { return typeof(TDerived).Name; }
}
public class MyOtherClass : MyClass<MyOtherClass> { }
public class HmmClass:MyOtherClass { }
void Main() {
MyOtherClass.MyStaticMethod().Dump(); //linqpad says MyOtherClass
HmmClass.MyStaticMethod().Dump(); //linqpad also says MyOtherClass
}
Here, you do need to update the subclass - but only in a minor fashion.