我正在尝试将列表从一个表单类传递到另一个表单类。这是代码:
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
}
}
}
然后在我的
BranchOverview
类中:List<Branch> branch = new List<Branch>();
public BranchOverview(List<Branch> myArgus)
{
InitializeComponent();
branch = myArgus;
}
运行代码时,出现以下错误:
Inconsistent accessibility: parameter type 'System.Collections.Generic.List<Argus.Branch>' is less accessible than method 'Argus.BranchOverview.BranchOverview(System.Collections.Generic.List<Argus.Branch>)'
最佳答案
您必须声明Branch
为公开:
public class Branch {
. . .
}