如何解决错误:可访问性不一致:通用c#接口的参数类型?

VJa*_*ain 13 c#

在将此代码写入我的项目时,我收到了错误

错误1可访问性不一致:字段类型'System.Collections.Generic.List<Jain_milan.Childrendata>'比字段更难访问'Jain_milan.addchild.m_children'
错误2可访问性不一致:参数类型'System.Collections.Generic.List<Jain_milan.Childrendata>'比方法更难访问'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
            }
Run Code Online (Sandbox Code Playgroud)

Lui*_*ipe 27

如果没有发布您的相关代码,我会试着预感:

Childrendata被声明为not-public和(我们可以看到)变量m_children是public

因此,公共变量无法公开不太容易访问的类型,在本例中为Childrendata

此外,您可能想要的是将m_children变为私有,这通常是最佳做法


D S*_*ley 6

我的猜测是Childrendata该类是private(或者internal,或者internal通过不指定可见性修饰符隐式)

既然List<Childrendata> m_children是公开的,也Childrendata需要公开.

Childrendatapublic,你应该没事.