我試圖簡化幾個與數組長的聲明,我在這裏發現了類似的問題,但我無法弄清楚我哪裏出錯了。代碼如下:數組的邊界索引C#
if (coursechoice.Text == ("Subsidiary Diploma"))
{
var grade = new[] { grade1, grade2, grade3, grade4, grade5, grade6, grade7, grade8, grade9, grade10, grade11, grade12, grade13, grade14, grade15, grade16, grade17, grade18 };
var unitselect = new[] { unitselect1, unitselect2, unitselect3, unitselect4, unitselect5, unitselect6, unitselect7, unitselect8, unitselect9, unitselect10, unitselect11, unitselect12, unitselect13, unitselect15, unitselect16, unitselect17, unitselect18 };
for (var i = 3; i < 18; i++)
{
grade[i].Enabled = false;
unitselect[i].Enabled = false; // I get index out of bounds of the array here
}
,如果你能幫助grade[I].Enabled= false;
工作正常,但其只是不工作unitselect,感謝代碼。
unitselect14 is missing –
你錯過了'unitselect14' – AbZy