可访问性、属性类型不一致

本文关键字:类型 不一致 属性 访问 | 更新日期: 2023-09-27 18:24:04

我知道Stack Overflow上有很多关于这方面的问题,所以如果这些解决方案真的对我有效,我就不会问这个问题了

不一致的可访问性错误C#

可访问性不一致:属性类型

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

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>,问题是在ViewModel类的某个地方定义了一个额外的内部类class MachineRow

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