我想如下創建使用VS2005在C#類:C#IList的參數會導致不一致的無障礙
public class MyClass
{
private string reference;
private IList<MyClassItem> items;
public MyClass(string reference, IList<MyClassItem> items) // error here
{
this.reference = reference ;
this.items = items;
}
public string Reference { get { return this.reference ; } set { this.reference = value; } }
public IList<MyClassItem> Items { get { return this.items; } set { this.items = value; } } // error line
}
public class MyClassItem
{
private string id;
private string name;
public MyClassItem(string id, string name)
{
this.id= id;
this.name= name;
}
public string Id{ get { return this.id; } set { this.id= value; } }
public string Name { get { return this.name; } set { this.name= value;}}
}
我得到了錯誤:
Inconsistent accessibility: parameter type '
System.Collections.Generic.IList<Library.Model.MyClassItem>
' is less accessible than method 'Library.Model.MyClass.Jurnal(string, System.Collections.Generic.IList<Library.Model.MyClassItem>)
' D:...\MyClass.cs 15 16 Library Error 4 Inconsistent accessibility: property type 'System.Collections.Generic.IList<Library.Model.MyClassItem>
' is less accessible than property 'Library.Model.MyClass.Items' D:...\MyClass.cs 28 34 Library
絕對*您當然可以* MyClassItem是公開的嗎?你能否提供證明問題的[mcve]?這些類是否嵌套? –
發佈的代碼不會導致任何錯誤。複製/粘貼或縮短代碼時發生錯誤。 –
@JonSkeet對我錯過了我的代碼中MyClassItem中的'public'...謝謝你們有一個美好的一天 – Jackie