Skip to main content
 首页 » 编程设计

c#之为什么我的方法声明会产生不一致的可访问性错误

2024年02月13日15小虾米

我正在使用以下代码从数据库中获取数据,

IList<MyListDB> MyList = this.GetMyList(); 

和 GetMyList() 函数,

public IList<MyListDB> GetMyList() 
    { 
        IList<MyListDB> MyList = null; 
        using (MyDataContext db = new MyDataContext(strConnectionString)) 
        { 
            IQueryable<MyListDB> EmpQuery = from Emp in db.Details select Emp; 
            MyList = EmpQuery.ToList(); 
        } 
        return MyList; 
    } 

但是我收到一个错误提示,

Inconsistent accessibility: return type 'System.Collections.Generic.IList<MyExpense.Values.MyListDB>' is less accessible than method 'MyExpense.Values.MyPanorama.GetMyList()' 

可能是什么问题? 提前致谢!

请您参考如下方法:

MyListDB 类型需要声明为public。

您的方法是公开的,因此它返回的类型也需要公开(如果不是,您还可以从任何地方访问它吗?)。