Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

c#

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

Error 1 Inconsistent accessibility: field type 'System.Collections.Generic.List<Jain_milan.Childrendata>' is less accessible than field 'Jain_milan.addchild.m_children'
Error 2 Inconsistent accessibility: parameter type 'System.Collections.Generic.List<Jain_milan.Childrendata>' is less accessible than method 'Jain_milan.addchild.addchild(System.Collections.Generic.List<Jain_milan.Childrendata>)'

namespace Jain_milan
{
        public partial class addchild : Form
        {
            List<Label> label = new List<Label>();
            List<TextBox> textbox = new List<TextBox>();
            List<ComboBox> combobox = new List<ComboBox>();
            List<DateTimePicker> datetimepicker = new List<DateTimePicker>();
            public List<Childrendata> m_children = new List<Childrendata>();
            public addchild(List<Childrendata> children)
            {
                InitializeComponent();
                this.m_children = children; //Initialize the same List as sent by Mainform
            }
like image 206
VJain Avatar asked May 07 '13 13:05

VJain


3 Answers

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

like image 74
Luis Filipe Avatar answered Nov 13 '22 11:11

Luis Filipe


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.

like image 42
D Stanley Avatar answered Nov 13 '22 11:11

D Stanley


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.

like image 2
Damien_The_Unbeliever Avatar answered Nov 13 '22 09:11

Damien_The_Unbeliever