2016-04-24 1 views
-1

Я пытаюсь создать класс в C# с помощью VS2005 следующим образом:параметр 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 в моем коде ... спасибо, ребята, у вас отличный день – Jackie

ответ

0

Единственная проблема, которую я могу себе представить, IST, что вы определили MyClassItem как часть другого класса, Ist частные, защищенные или внутренние, например:

internal class MyOtherClass 
{ 
    //MyOtherClass properties and functions 

    public class MyClassItem 
    { 
    } 

} 

Просто переместите MyClassItem прямо в пространство имен, и это должно решить проблему.

Смежные вопросы