小编Y2J*_*Y2J的帖子

索引超出了数组错误的范围(C#)

我有以下代码从Listbox获取值.我选了三位老师.当'i'值达到3时,它显示' 索引超出了数组的范围 '错误

    string selectedTeachers = Request["SelectedTeachersList"];
    int[] teachers_ID = Array.ConvertAll(selectedTeachers.Split(','), int.Parse);
    for (int i = 0; i <= teachers_ID.Length; i++)
    {
      int Id = teachers_ID[i];
    }
Run Code Online (Sandbox Code Playgroud)

c# arrays for-loop indexoutofboundsexception

1
推荐指数
1
解决办法
127
查看次数

标签 统计

arrays ×1

c# ×1

for-loop ×1

indexoutofboundsexception ×1