我目前正在使用类和构造函数。我在构造函数中有一个名为current
equals的 sint 变量0
。现在,当我单击按钮时,我试图增加属性current
,然后调用 GetNextTree 来显示。但是current++
从按钮单击递增时,我收到此错误:does not exist in current context
. 那么增加的正确方法是current
什么?
public class fruit_trees
{
}
public class ListForTrees
{
public int current;
public fruit_trees GetNextTree()
{
current = 0;
fruit_trees ft = first_tree;
int i = 0;
while (i != current)
{
ft = ft.next_tree;
i++;
}
return ft;
}
}
private void ShowNextItem_Click(object sender, EventArgs e)
{
//Show Last Item
fruit_trees obj = mainlist.GetNextTree();
if (obj == null)
{
labelSpecificTree.Text = "No more trees!";
}
else
{
//error: current does not exist?
current++
labelSpecificTree.Text = obj.next_tree.GetTreeType.ToString();
}
}