首页 文章

可访问性不一致:参数类型比方法更难访问

提问于
浏览
0

得到以下错误 . 我在点击第一张表格上的按钮后尝试跳转到新表格 . 我需要传递一个类对象列表 .

错误1可访问性不一致:参数类型'System.Collections.Generic.List'不如方法'Preferred_Customer.AddCustomer.AddCustomer(System.Collections.Generic.List)'C:\ Users \ Ron \ Documents \ Visual Studio 2013 \ Projects \ Preferred Customer \ Preferred Customer \ 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;

    }

有人能说出我错过的东西吗?

2 回答

  • 1

    PrefferedCustomer 从内部更改为公共 . (我猜 PrefferedCustomer 是内部的,除非在另一个类声明中)或者将 AddCustomer 更改为 internal 以匹配辅助功能级别

    internal partial class AddCustomer : Form
    
  • 2

    这个错误来自于尝试在一个类中公开一个类型,而这个类的级别比它声明的级别更“开放” . 例如:

    internal interface ISomethingManager {
      // ...
    }
    
    public interface IDoSomething {
      public void DoSomething( ISomethingManager manager );
    }
    

    在此示例中, ISomethingManager 是内部的,但您将其公开为public IDoSomething 中的方法参数 . 如果另一个程序集想要调用 IDoSomething.DoSomething() ,则需要知道 ISomethingManager ,这在内部时是不可能的 .

相关问题