【问题标题】:Memeber 'Model.Fields' cannot be accessed with an instance reference; quailfy it with a type name instead [duplicate]无法使用实例引用访问成员“Model.Fields”;用类型名称来限定它[重复]
【发布时间】:2020-05-26 12:25:50
【问题描述】:

我在我的模型中添加了一个列表,如下所示:

    public static List<string> Fields
    {
        get
        {
           var results = new List<string>() { "Name", "Date", "Address", "..." };
            return results;

        }
    }

当我尝试在我的方法中访问我的列表时,我收到以下错误: “无法使用实例引用访问成员‘Model.Fields’;改为使用类型名称对其进行限定”

【问题讨论】:

标签: c#


【解决方案1】:

因为Fields 是静态的,如果你这样做:

MyClass test = new MyClass();

您不使用test 访问Fields,而是使用类名-MyClass

//wrong
test.Fields

//right
MyClass.Fields

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2023-04-08
    • 2015-01-31
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多