可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
I'm trying to pass a list from one form class to another. Here's the code:
List myArgus = new List(); private void btnLogin_Click(object sender, EventArgs e) { // Get the selected branch name string selectedBranch = lbBranches.SelectedItem.ToString(); for (int i = 0; i
And then in my BranchOverview class:
List branch = new List(); public BranchOverview(List myArgus) { InitializeComponent(); branch = myArgus; }
When I run the code, I get this error:
Inconsistent accessibility: parameter type 'System.Collections.Generic.List' is less accessible than method 'Argus.BranchOverview.BranchOverview(System.Collections.Generic.List)'
回答1:
You have to declare Branch to be public:
public class Branch { . . . }
回答2:
As the error message says, the type of all parameters of a method must be at least as accessible as the method itself.
You need to make your Branch class public if you are using it as a parameter in a public method.
public class Branch { .... } ^^^^^^
Alternatively you could change your method to be internal instead of public.
internal BranchOverview(List myArgus) ^^^^^^^^
回答3:
The constructor of BranchOverview is public, which means that all types involved in its formal parameter list must also be public. Most probably you have not provided an accessibility specification for Branch, i.e. you have written
class Branch { ... }
which means that Branch is internal.
回答4:
By default, fields of a class are private if no access modifier is present ...
回答5:
Change:
List myArgus = new List();
to be public.