问题描述
我没有写这段代码,所以我不确定这个错误是怎么回事。
checkedListBox1是一个公共对象。为什么错误表明在for循环中期望''类''是
?是因为该方法是静态的吗?
这是错误和代码:
C:\ ... \ Form1.cs(1130) ):''APP.mainForm.checkedListBox1''表示''字段''
,其中''类''是预期的
public static void MenuItem_Click(object sender ,System.EventArgs e)
{
for(int i = 0; i< checkedListBox1.Items.Count; i ++)//<<<< 1130行
{
checkedListBox1.SetItemChecked(i,false);
}
}
同样出错:C:\ ... \ newPrompt.cs(172):对象引用
是非静态字段方法,或者属性
''APP.mainForm.MenuItem''
private void button1_Click(object sender,System.EventArgs e)
{
for(int o = mainForm.historyMenuItem.MenuItems.Count-1; o> = 0; o--)
mainForm.historyMenuItem.MenuItems.RemoveAt(o);
}
帮助表示赞赏。
For我只能猜测这个错误。它是mainForm类的名称吗?
HTH
B \ rgds
I didn''t write this code so I''m not sure what is going on with this error.
checkedListBox1 is a public object. Why does the error say that it is
expecting a ''class'' in a for loop? Is it because the method is static?
Here is the error and the code:
C:\...\Form1.cs(1130): ''APP.mainForm.checkedListBox1'' denotes a ''field''
where a ''class'' was expected
public static void MenuItem_Click(object sender, System.EventArgs e)
{
for(int i = 0; i<checkedListBox1.Items.Count;i++)//<<<<line 1130
{
checkedListBox1.SetItemChecked(i,false);
}
}
Also getting an error saying: C:\...\newPrompt.cs(172): An object reference
is required for the nonstatic field, method, or property
''APP.mainForm.MenuItem''
private void button1_Click(object sender, System.EventArgs e)
{
for(int o = mainForm.historyMenuItem.MenuItems.Count-1; o>=0;o--)
mainForm.historyMenuItem.MenuItems.RemoveAt(o);
}
Help is appreciated.
For this error I can only guess. Is it mainForm the name of the class?
HTH
B\rgds
100
这篇关于静态方法有问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!