如何解决错误:可访问性不一致:参数类型为通用的C#接口? [英] How to solve the Error: Inconsistent accessibility: parameter type for generic c# interface?

查看:1185
本文介绍了如何解决错误:可访问性不一致:参数类型为通用的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>)




 命名空间Jain_milan 
{
公共部分类的addChild:表
{
名单,LT;标签>标签=新的List<标签>();
名单,LT;文本框>文本框=新的List<&文本框GT;();
名单,LT;组合框>组合框=新的List<&组合框GT;();
名单,LT;&的DateTimePicker GT;的DateTimePicker =新的List<&的DateTimePicker GT;();
公开名单< Childrendata> m_children =新的List< Childrendata>();
公众的addChild(列表< Childrendata>子女)
{
的InitializeComponent();
this.m_children =儿童; //初始化同一个列表由MainForm中
}


解决方案

如果没有可以发布您的整个相关的代码,我会尝试一种预感:



类的 Childrendata 被声明为不公开和(我们可以看到),变量 m_children 是公共



Threfore公共变量不能暴露更少的可访问类型,在这种情况下, Childrendata



此外,你可能想要的是打开的 m_children 私人以及这通常是最好的做法。


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
            }

解决方案

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

这篇关于如何解决错误:可访问性不一致:参数类型为通用的C#接口?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆