Inconsistent Accessibility using lists

2019-08-23 04:27发布

问题:

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.