How to solve the Error: Inconsistent accessibility: parameter type for generic c# interface?

后端 未结 5 825
不知归路
不知归路 2021-01-04 06:25

On writting this code into my project i am getting the error that

Error 1 Inconsistent accessibility: field type \'System.Collections.Gene

相关标签:
5条回答
  • 2021-01-04 06:54

    Without posting your entire relevant code i'll try a hunch:

    the class Childrendata is declared as not-public and (as we can see) the variable m_children is public

    Threfore a public variable cannot expose a less accessible type, in this case, Childrendata

    Additionally, what you might want is to turn m_children private as well as this is usually the best practice

    0 讨论(0)
  • 2021-01-04 06:54

    Childrendata isn't public. How, then, do you expect someone calling addchild to be able to provide the required parameter?

    The obvious fixes are to change the accessibility of addchild or Childrendata.

    0 讨论(0)
  • 2021-01-04 06:54

    You can't use access modifier two times. if you used public class than you should not use the instance public. public partial class Record : ContentPage { List datas = new List() { I used record class public but not list.

    0 讨论(0)
  • 2021-01-04 07:02

    just make the method addChilde(List<object> childeren) or only object not list then do this

    var Listchild = childeren as List<childe>;
    
    0 讨论(0)
  • 2021-01-04 07:03

    My guess is that the Childrendata class is private (or internal, or implicitly internal by not specifying a visibility modifier)

    Since List<Childrendata> m_children is public, Childrendata needs to be public as well.

    Change Childrendata to public and you should be fine.

    0 讨论(0)
提交回复
热议问题