索引超出范围..必须是非负数且小于集合的大小。参数名称:index

时间:2018-02-05 09:50:42

标签: c# asp.net for-loop

这是我的代码:

for (i = j; i <= e.curpos; i++)
        {               
            Question q = e.questions[i];-- here exception is occuring
            // display details of question
            dr = dts.NewRow();
            dr["no"] = i+1;
            dr["enterquestion"] = q.enterquestion;
            dr["optiona"] = q.optiona;
            dr["optionb"] = q.optionb;
            dr["optionc"] = q.optionc;
            dr["optiond"] = q.optiond;
            dts.Rows.Add(dr);
        }
循环完成后,

Question q = e.questions[i]正在发生异常

1 个答案:

答案 0 :(得分:0)

错误是e.curpos等于或大于e.questions.length,或j小于0.您需要使用断点或写入控制台日志才能看到哪个值不正确。