小编Joh*_*man的帖子

派生类在自己的静态方法中调用基类的静态方法

我已阅读了以下SO文章

所有这些似乎都非常接近我的问题,并且有很好的答案,但他们似乎没有回答我的问题,只是说我需要使方法非静态.

一个例子:

abstract public class baseClass
{
    private static List<string> attributeNames = new List(new string {"property1","property2"});
    // code for property definition and access
    virtual public static bool ValidAttribtue(string attributeName)
    {
        if (attributeNames.Contains(attributeName))
            return true;
        else
            return false;
    }
}
class derivedA : baseClass
{
    private static List<string> attributeNames = new List(new string {"property3","property4"});
    // code for property definition and access
    public static override bool ValidAttribute(string attributeName)
    {
        if (attributeNames.Contains(attributeName))
        {
            return true;
        }
        else
        {
            return …
Run Code Online (Sandbox Code Playgroud)

c# static-methods derived-class

5
推荐指数
1
解决办法
4368
查看次数

标签 统计

c# ×1

derived-class ×1

static-methods ×1