由於某些原因,在這個for循環中,i達到1,並導致index out of range
錯誤。 Items.Count
等於4,我檢查使用斷點,StockList.Count
也等於4.我似乎無法弄清楚爲什麼我達到一個,任何想法?For-Loops很奇怪
for (int i = 0; i <= (Items.Count/4) - 1; i++)
{
for (int ii = 0;ii <= Program.StockList.Count - 1;i++)
{
if (Items[(i * 4) + 3] == Program.StockList[ii].ID) //Crash here
{
MessageBox.Show(Program.StockList[ii].Name + " Match!");
}
}
}
你在你的第二個for循環遞增'i'。發生這種事時我討厭它。 – dialer
選擇好的變量名稱是該戰鬥的90%,'i'和'ii'不是很好的名字。 –
爲了加入到變量命名的戰鬥中,使用循環的一個很好的例子是它使用i作爲第一維,j作爲第二維,k作爲第三維。 – BAS