0

I wrote this bit of code to access a DataTable, however it throws the OutOfBounds Exception.

for (int i = 0; i < table.Rows.Count; i++)
{
  //Computing Values of v1, v2
  v_1 = v_1 + RGen(0, 2) * (x1_l - x1_best) + RGen(0, 2) * (x1_best - (double)table.Rows[0].ItemArray[i]);
  v_2 = v_2 + RGen(0, 2) * (x2_l - x2_best) + RGen(0, 2) * (x2_best - (double)table.Rows[1].ItemArray[i]);

  x1.Add(Relax((double)table.Rows[0].ItemArray[i] + v_1));
  x2.Add(Relax((double)table.Rows[1].ItemArray[i] + v_2));
}

The DataTable is surely populated. What have I Missed?

1 Answer 1

2

i is an index of row, but you are using it to access ItemsArray (which are cells). You should use columns instead

for (int i = 0; i < table.Columns.Count; i++)
{
   //...
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.