私は現在、クラスとコンストラクターを使用しています。コンストラクター内にcurrent
等しいという名前の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();
}
}