0

This is my code :

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] here after the loop complete the exception is occurring

Sibeesh Venu
  • 18,755
  • 12
  • 103
  • 140
  • 2
    What's e ? What's j ? Hard to say what's wrong without knowing all of your code... – cslotty Feb 05 '18 at 09:54
  • e is obj of Examination Class file and Question is also a class file and j is a variable – Leo Kamal Raj Feb 05 '18 at 10:16
  • How does `e.curpos` relate to the number of elements in `e.questions`? For this code to work, `e.curpos` must be _less than_ `e.quesions.Length`. If `e.curpos` is _equal to_ `e.questions.Length`, then just change the `i <= e.curpos` to be `i < e.curpos`. – Trevor Feb 05 '18 at 10:24

1 Answers1

0

What's wrong is e.curpos is equal to or greater than e.questions.length, or j is less than 0. You'll need to use a breakpoint or write to the console log to see which value is incorrect.