0
我正在爲我的類分配做一個自定義迭代器,並且我得到一個索引超出界限,但我看不到在哪裏。 當我調試它停止在最後一次迭代(計數39,停在索引39)自定義迭代器索引超出範圍
我不知道在迭代器中的問題仍然存在。
public override bool NextCourse(DataSet courseDS, DataView courseView, ref int currIndex)
{
if (courseView.Count == 0)
return false;
int nextIndex = currIndex + 1;
if (nextIndex >= courseView.Count -1)
{
currIndex = nextIndex;
return true;
}
if (currIndex < 0)
{
currIndex = 0;
return true;
}
string currCourseNumber = (string)courseView[currIndex][(int)CourseListQueries.GetCourseListCols.CourseNumber];
string courseNumber = String.Empty;
currIndex++;
do
{
courseNumber = (string)courseView[currIndex][(int)CourseListQueries.GetCourseListCols.CourseNumber];
if (String.Compare(courseNumber, currCourseNumber,true) != 0)
break;
currIndex++;
}
while (currIndex < courseView.Count);
return (currIndex < courseView.Count);
}// end NextCourse
堆棧跟蹤:
Index 39 is either negative or above rows count.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.IndexOutOfRangeException: Index 39 is either negative or above rows count.
Source Error:
An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.
Stack Trace:
[IndexOutOfRangeException: Index 39 is either negative or above rows count.]
System.Data.DataView.GetRow(Int32 index) +5259337
System.Data.DataView.get_Item(Int32 recordIndex) +12
FIMS_Courses.Controls.CourseTable.GradTable.GradTable.InitializeControls(GenericContainer container) +4978
Telerik.Sitefinity.Web.UI.SimpleView.CreateChildControls() +52
System.Web.UI.Control.EnsureChildControls() +83
System.Web.UI.Control.PreRenderRecursiveInternal() +42
System.Web.UI.Control.PreRenderRecursiveInternal() +168
System.Web.UI.Control.PreRenderRecursiveInternal() +168
System.Web.UI.Control.PreRenderRecursiveInternal() +168
System.Web.UI.Control.PreRenderRecursiveInternal() +168
System.Web.UI.Control.PreRenderRecursiveInternal() +168
System.Web.UI.Control.PreRenderRecursiveInternal() +168
System.Web.UI.Control.PreRenderRecursiveInternal() +168
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +974
請包括堆棧跟蹤,並指明你要除外。 (如果可能的話,我會嘗試使用迭代器塊...這一切看起來都非常複雜。) –