c# - 可访问性、属性类型不一致

标签 c# compiler-errors

我知道 Stack Overflow 上有很多关于这个问题的答案,所以如果这些解决方案真的对我有用,我就不会问这个问题。以下是我看过的一些问题:

Inconsistent accessibility error C#

Inconsistent accessibility: property type

根据上述问题的每个解决方案,我已将我的所有类(class)都指定为公开类(class),但我仍然遇到相同的错误。这是我的代码:

namespace TestResourceManager
{
    public class ViewModel
    {
        private List<string> m_ViewOptions = null;
        private List<MachineRow> m_ViewChoices = null;

        public ViewModel()
        {
            m_ViewOptions = new List<string>();
            m_ViewOptions.Add("item1");
            m_ViewOptions.Add("item2");
            m_ViewChoices.Add(new MachineRow("machinename1", "builddefinition1", "description1", "envname1", "envtype1"));
            m_ViewChoices.Add(new MachineRow("machinename2", "builddefinition2", "description2", "envname2", "envtype2"));
        }

        public List<string> ViewOptions
        {
            get { return m_ViewOptions; }
        }

        public List<MachineRow> ViewChoices
        {
            get { return m_ViewChoices; }
        }
    }
    public class MachineRow
    {
        private string MachineName, BuildDefinition, Description, EnvName, EnvType;

        public MachineRow(string _MachineName, string _BuildDefinition, string _Description, string _EnvName, string _EnvType)
        {
            this.MachineName = _MachineName;
            this.BuildDefinition = _BuildDefinition;
            this.Description = _Description;
            this.EnvName = _EnvName;
            this.EnvType = _EnvType;
        }
    }
}

这个错误:
Inconsistent accessibility: property type 'System.Collections.Generic.List<TestResourceManager.ViewModel.MachineRow>' is less accessible than property 'TestResourceManager.ViewModel.ViewChoices'

正在这条线上发生:
public List<MachineRow> ViewChoices

有谁知道为什么其他人的解决方案不适用于我的情况?非常感谢任何帮助!

最佳答案

粘贴的代码不是完整的代码。给出错误消息:System.Collections.Generic.List<TestResourceManager.**ViewModel**.MachineRow> ,问题是有一个额外的内部类,class MachineRow在您的ViewModel 中的某处定义类(class)。

public class ViewModel
{
   // Somewhere before the closing brace, you're defining a MachineRow class that is not public, ie:
   class MachineRow {}

关于c# - 可访问性、属性类型不一致,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17757221/

相关文章:

c# - 具有多个值的资源文件(或通过代码访问注释列)

javascript - Asp.Net Kendo UI事件函数未定义 "change is not defined"

c# - 如何读取.Doc模板文件并使用值编辑模板?

c++ - 静态分配的可变大小数组如何在 C++ 中工作?

c# - 确定 SSL/TLS 加密?

c# - 设置 TabControl 对齐属性。 C# 窗体

visual-studio-2013 - 找不到元数据文件.dll CSC错误

c# - MVC : An unhandled exception of type 'System.StackOverflowException' occurred in System.Core.dll

java - 找不到符号错误

c - 'asm' : __asm__ __volatile__ 中不可能的约束