簡體   English   中英

可訪問性不一致:參數類型比方法更難訪問

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM