Должен быть неотрицательным и меньше размера коллекции
Whats wrong with this code why this exception occur . System.ArgumentOutOfRangeException: Index was out of range. Must be non-negative and less than the size of the collection. Parameter name: index at System.ThrowHelper.ThrowArgumentOutOfRangeException() at System.Collections.Generic.List`1.get_Item(Int32 index) at CourseAcademics_ProgressReports.EvalResult(List`1[] a, List`1[] totalmarks, List`1 names, Int32 subjectcount, DataTable dt) in c:\Users\Administrator\Documents\Visual Studio 2010\Projects\RootsERPWeb\ERPWeb\CourseAcademics\ProgressReports.aspx.cs:line 315
public void EvalResult(List<double>[] a, List<double>[] totalmarks, List<string> names, int subjectcount, DataTable dt) { dt1 = new DataTable(); try { for (int i = 0; i < a[0].Count; i++) { string[] xxx = new string[subjectcount + 4]; xxx[0] = names[i]; for (int j = 1; j <= subjectcount; j++) { double perc = Math.Round((a[j - 1][i] / totalmarks[j - 1][i]) * 100, 2); xxx[j] = a[j - 1][i] + "/" + totalmarks[j - 1][i]; } double obtainedmarkstotal = 0; double totalmark = 0; for (int k = 0; k < subjectcount; k++) { obtainedmarkstotal += a[k][i]; totalmark += totalmarks[k][i]; } double perctotal = Math.Round(obtainedmarkstotal / totalmark * 100, 2); xxx[subjectcount + 1] = obtainedmarkstotal + "/" + totalmark; xxx[subjectcount + 2] = perctotal.ToString() + "%"; xxx[subjectcount + 3] = getgrade(perctotal); dt.Rows.Add(xxx); } gvforawards.Visible = true; Label1.Text = ""; dt1 =(DataTable) dt; Session["result"]=dt1; gvforawards.DataSource = dt1; gvforawards.DataBind(); int s = 0; int columns_count = gvforawards.Columns.Count; foreach (GridViewRow gvr in gvforawards.Rows) { ((HyperLink)gvr.Cells[0].Controls[0]).NavigateUrl="~/MarkSheet.aspx?; s++; } } catch(Exception ex) { gvforawards.Visible = false; Label1.ForeColor = Color.Red; Label1.Visible = true; Label1.Text = ex.ToString(); } }
Что я уже пробовал:
если значение j равно 9, то возникает исключение.Может ли кто-нибудь сказать мне, какую ошибку я совершил ?