C#中:如何调用基类的静态方法从派生类的静态方法?
在C#中,我有基类产品和派生类的Widget。
In C#, I have base class Product and derived class Widget.
产品包含一个静态方法的MyMethod()。
Product contains a static method MyMethod().
我想从静态方法Widget.MyMethod()调用静态方法Product.MyMethod()。
I want to call static method Product.MyMethod() from static method Widget.MyMethod().
我不能使用base关键字,因为这仅适用于实例方法。
I can't use the base keyword, because that only works with instance methods.
我可以调用Product.MyMethod()明确,但如果我以后更改的Widget从另一个类派生,我不得不修改方法
I can call Product.MyMethod() explicitly, but if I later change Widget to derive from another class, I have to revise the method.
有一些语法在C#类似于基地,让我从一个派生类的静态方法?
Is there some syntax in C# similar to base that allows me to call a static method from a base class from a static method of a derived class?
静态
方法基本上是从面向对象的概念,回退的方法。因此,他们不是在继承层次结构非常灵活,它不可能直接做这样的事情。
static
methods are basically a method to fallback from object oriented concepts. As a consequence, they are not very flexible in inheritance hierarchies and it's not possible to do such a thing directly.
我能想到的最接近的是一个使用指令
The closest thing I can think of is a using
directive.
using mybaseclass = Namespace.BaseClass;
class MyClass : mybaseclass {
static void MyMethod() { mybaseclass.BaseStaticMethod(); }
}