【问题标题】:Inconsistent accessibility: field type 'System.Collections.Generic.Dictionary<> is less accessible than other field可访问性不一致:字段类型 'System.Collections.Generic.Dictionary<> 比其他字段更难访问
【发布时间】:2014-06-25 11:17:30
【问题描述】:
[Serializable]
class LotInfo
{
    public int ID { get; set; }
    public string DonorName { get; set; }
    public string BloodGroup { get; set; }
    public string RhFactor { get; set; }
    public string Address { get; set; }
    public string TelephoneNumber { get; set; }

    public LotInfo(int id)
    {
        ID = id;
    }

    public LotInfo()
    {

    }
}

[Serializable]
public class LotInfoDatabase
{
    public Dictionary<int, LotInfo> dicLotDatabase = new Dictionary<int, LotInfo>();
    public int LastID { get; set; }
    public int GetNewID()
    {
        return (++LastID);
    }
}

伙计们,我正在为 datagridview 做 Serializer 以保存和加载数据。但是这个错误来了......

可访问性不一致:字段类型“System.Collections.Generic.Dictionary”的可访问性低于字段“Blood_Bank_Management.LotInfoDatabase.dicLotDatabase”

我是stackoverflow的新手,如果我做错了,请原谅我。谢谢...

【问题讨论】:

  • 请添加与您使用的语言相对应的标签(c#?)。
  • 对不起,这是我第一次在stackoverflow中提问

标签: c# visual-studio field


【解决方案1】:

LotInfointernal 类,而不是 public,因为您没有为它指定任何修饰符。

然后你构造了一个Dictionary&lt;int, LotInfo&gt; 类型并尝试通过public 类型(LotInfoDatabase) 上的public 字段(dicLotDatabase) 公开它。制作 LotInfo public 将是解决此问题的一种方法,但我不确定这是否是您想要做的。

【讨论】:

  • 天哪,我真的犯了那个愚蠢的错误,现在它完美地工作了。谢谢你的教导。
猜你喜欢
  • 2023-03-24
  • 2012-10-11
  • 1970-01-01
  • 2018-03-07
  • 1970-01-01
  • 2012-10-27
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多