我正在尝试将列表从一个表单类传递到另一个表单类。这是代码:
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 {
. . .
}
关于c# - 参数比方法更难访问,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9726974/