[英]Inconsistent accessibility:parameter type is less accessible than a method
出现以下错误。 单击第一个表单上的按钮后,我试图跳至新表单。 我需要传递一个类对象列表。
错误1不一致的可访问性:参数类型'System.Collections.Generic.List'比方法'Preferred_Customer.AddCustomer.AddCustomer(System.Collections.Generic.List)'C:\\ Users \\ Ron \\ Documents \\ Visual Studio 2013 \\项目\\首选客户\\首选客户\\ AddCustomer.cs 18 16首选客户
这是创建表单的代码;
private void addCustomerButton_Click(object sender, EventArgs e)
{
AddCustomer myAddCustomer = new AddCustomer(preferredCustomerList);
myAddCustomer.ShowDialog();
}
这是AddCustomer的代码;
namespace Preferred_Customer
{
public partial class AddCustomer : Form
{
private List<PreferredCustomer> addCustomerList;
public AddCustomer(List<PreferredCustomer> inPreferredCustomerList)
{
InitializeComponent();
addCustomerList = inPreferredCustomerList;
}
有人能说出我的失踪吗?
将PrefferedCustomer
从内部更改为公共。 (我猜PrefferedCustomer
是内部的,除非在另一个类声明中)或将AddCustomer
更改为internal
以匹配可访问性级别
internal partial class AddCustomer : Form
出现此错误的原因是,尝试在类中公开比其声明的类“开放”的类型更多的类型。 例如:
internal interface ISomethingManager {
// ...
}
public interface IDoSomething {
public void DoSomething( ISomethingManager manager );
}
在此示例中, ISomethingManager
是内部的,但您将其作为公共IDoSomething
的方法参数公开。 如果另一个程序集想要调用IDoSomething.DoSomething()
,则需要了解ISomethingManager
,这在内部时是不可能的。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.