【发布时间】:2009-12-04 19:34:42
【问题描述】:
我正在尝试在 C# 中做这样的事情
public class ParentClass {
public static ParentClass GetSomething()
{
var thing = new // ?????
return thing;
}
}
public class ChildClass : ParentClass {
}
然后我希望能够像这样调用子类的静态方法:
ChildClass blah = ChildClass.GetSomething();
例如在子类上调用静态方法时,我想实例化子类的一个实例。但我只想要在父级上定义的静态方法。这是可能吗?我会很高兴:
ChildClass blah = (ChildClass) ChildClass.GetSomething();
谢谢!
【问题讨论】:
标签: c# inheritance syntax static types