2017-06-03 70 views
0

List _list; string _total,_cash,_change,_date;参数类型'System.Collections.Generic.List <WindowsFormsApplication8.receipt''比方法更难以访问

public Form8(List<receipt> datasource, string total, string cash, string change, string date) 
{ 
    InitializeComponent(); 
    _list = datasource; 
    _total = total; 
    _cash = cash; 
    _change = change; 
    _date = date; 
} 

enter image description here

在这里,我得到了一个错误。

错误1可访问性不一致:参数类型 'System.Collections.Generic.List' 比方法更少可访问的“WindowsFormsApplication8.Form8.Form8(System.Collections.Generic.List,字符串,字符串,字符串,字符串) “C:\用户\ thush \文档\的Visual Studio 2012 \项目\ WindowsFormsApplication8 \ WindowsFormsApplication8 \ Form8.cs 18 16 WindowsFormsApplication8

+2

最有可能的'收据'类型是不公开的。公开。 – CodingYoshi

回答

0

除非你已经创建了自己的System.Collections.Generic.List<T>类错误是特指你receipt类。注意它的使用,其中的可访问性:

public Form8(List<receipt> ... 

这是一个public类(Form8)的转一部分。所以错误告诉你,这些东西比你需要的类型更容易访问,特别是receipt

从消费代码的角度来看,任何代码都可以看到你的Form8类,并且可以看到它的构造函数。但是,如果相同的消费代码不能请参阅receipt类,那么该构造函数将没有任何意义。编译器通过你看到的错误来防止这种情况发生。

总之,如果你想在这样的public方式使用receipt,然后receipt本身需要public

所以基本上就像你Form8类是public

public partial class Form8 : Form 
{ 
    //... 

所以必须在receipt类是:

public class receipt 
{ 
    //... 

(大多在猜测receipt类的声明,因为你不没有表现出来。)

+0

该怎么办?你能告诉我代码 – tagon

+0

@tagon:我已经用一个例子更新了答案。为了公开使用它,你只需要让“public”类。 – David

+0

非常感谢...... – tagon

相关问题