gpt4 book ai didi

c# - 索引超出数组范围 C#

转载 作者:行者123 更新时间:2023-11-30 18:51:00 25 4
gpt4 key购买 nike

我试图用数组简化一些长语句,我在这里发现了类似的问题,但我无法弄清楚哪里出错了。代码如下:

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 不起作用,如果你能提供帮助,谢谢。

最佳答案

Unitselect 仅包含 17 个项目,没有 unitselect14

关于c# - 索引超出数组范围 C#,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20188851/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com