【发布时间】:2013-12-09 12:09:58
【问题描述】:
我在一个数组(statsname)中有一定数量的元素。
其实是这样的
x[1] A_NAME
x[2] A_CATEGORY
x[3] ANOTHER_NAME
x[4] A_CATEGORY
我想要组合框中的类别。 我做了
int up =1;
foreach (string things in statsname)
{
//if the stat name doesnot contains TIME
//Only then we add it to the combobox.
if ((Convert.ToString(things[up]) == "CurrentNumber") || (Convert.ToString(things[up]) == "TotalNumber"))
{
tcomboBox1.Items.Add(things[up-1]);
}
up++;
if (up != statsname.Count())
{
tcomboBox1.Items.Add(things[up - 1]);
}
}
但是我得到一个错误提示
Array out of bound
为什么会这样? 我哪里做错了?
【问题讨论】:
-
因为它不满足条件,并且您将索引增加到甚至没有落在数组大小中的程度。请使用断点调试。