参数大于法不易进入 [英] Parameter is less accessible than method
本文介绍了参数大于法不易进入的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我试图从一种形式传递类的列表到另一个。下面的代码:
列表<&科GT; myArgus =新的List<分行及GT;();
私人无效btnLogin_Click(对象发件人,EventArgs五)
{
//获取选定的分支名
串selectedBranch = lbBranches.SelectedItem.ToString();
的for(int i = 0; I< myArgus.Count;我++)
{
如果(myArgus [I] ._ BRANCHNAME == selectedBranch)
{
//打开BranchOverview形式
BranchOverview branchOverview =新BranchOverview(myArgus [I]);
branchOverview.Show();
}
,否则
{
//分支不存在由于某种原因,
}
}
}
然后在我的 BranchOverview
类:
列表<&科GT;支=新的List<分行及GT;();
公共BranchOverview(列表<分行及GT; myArgus)
{
的InitializeComponent();
支= myArgus;
}
当我运行代码,我得到这个错误:
可访问性不一致:参数类型System.Collections.Generic.List< Argus.Branch>'比少的方法访问Argus.BranchOverview.BranchOverview( System.Collections.Generic.List< Argus.Branch>)
解决方案
您必须声明科
是公共的:
公开Branch类{
。 。 。
}
I'm trying to pass a list from one form class to another. Here's the code:
List<Branch> myArgus = new List<Branch>();
private void btnLogin_Click(object sender, EventArgs e)
{
// Get the selected branch name
string selectedBranch = lbBranches.SelectedItem.ToString();
for (int i = 0; i < myArgus.Count; i++)
{
if (myArgus[i]._branchName == selectedBranch)
{
// Open the BranchOverview form
BranchOverview branchOverview = new BranchOverview(myArgus[i]);
branchOverview.Show();
}
else
{
// Branch doesn't exist for some reason
}
}
}
And then in my BranchOverview
class:
List<Branch> branch = new List<Branch>();
public BranchOverview(List<Branch> myArgus)
{
InitializeComponent();
branch = myArgus;
}
When I run the code, I get this error:
Inconsistent accessibility: parameter type 'System.Collections.Generic.List<Argus.Branch>' is less accessible than method 'Argus.BranchOverview.BranchOverview(System.Collections.Generic.List<Argus.Branch>)'
解决方案
You have to declare Branch
to be public:
public class Branch {
. . .
}
这篇关于参数大于法不易进入的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文