Inconsistent Accessibility using lists

浪尽此生 提交于 2019-12-11 20:21:10

问题


I'm trying to create a list of class instances for storing information, but I'm getting this error:

Error 1 Inconsistent accessibility: property type 'System.Collections.Generic.List<POS_System.ReportReciepts>' is less accessible than property 'POS_System.Reports24Hours.recieptlist'

Any clue why? I've tried figuring out but I have no idea whats throwing this. Heres my code where the error is being thrown and my class. Thanks!

public partial class Reports24Hours : Form
{
    string category = "";
    public int WhichReciept = 0;
    public static List<ReportReciepts> recieptlist { get; set; } //Error here
    ...
}

.

class ReportReciepts
{
    public string[] Quantity { get; set; }
    public string[] ItemName { get; set; }
    public string[] Price { get; set; }
}

回答1:


Your ReportReceipts needs to be Public. Essentially you're making a public list of items, but the type of item is private, so no one can see it. This should work:

public partial class Reports24Hours : Form
{
    string category = "";
    public int WhichReciept = 0;
    public static List<ReportReciepts> recieptlist { get; set; } //Error here
    ...
}



public class ReportReciepts
{
    public string[] Quantity { get; set; }
    public string[] ItemName { get; set; }
    public string[] Price { get; set; }
}



回答2:


You need to make ReportReciepts public. The default access modifier for a class is internal, but you're attempting to return a List of ReportReciepts from a public property. Any type exposed via a public property must itself be public.



来源:https://stackoverflow.com/questions/19986063/inconsistent-accessibility-using-lists

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!