2016-04-24 4 views
-1

を引き起こし、私は次のように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

+5

「MyClassItem」はあなたがそれを公開したように公開されていますか?問題を示す[mcve]を提供できますか?これらのクラスはネストされていますか? –

+0

投稿されたコードはエラーを起こさない。コピー/貼り付け中やコード短縮時にエラーが発生しました。 –

+0

@ JonSkeet私のコードでMyClassItemの 'public'を忘れてしまった...皆さんありがとう – Jackie

答えて

0

私はそのIST想像できる唯一の問題を他のクラスの一部としてMyClassItemを定義しました。このクラスは、プライベート、プロテクト、または内部ではありません。たとえば、

internal class MyOtherClass 
{ 
    //MyOtherClass properties and functions 

    public class MyClassItem 
    { 
    } 

} 

MyClassItemをネームスペースに直接移動すると、これで問題は解決されるはずです