0
private void Right_Click(object sender, EventArgs e)
{
using (var ctx = new NORTHWNDEntities())
{
if (currentIndex < ctx.Employees.Count())
{
currentIndex++;
Employee empl = ctx.Employees.ToList().ElementAt(currentIndex);
Id.Text = empl.EmployeeID.ToString();
FirstName.Text = empl.FirstName;
LastName.Text = empl.LastName;
DateOfBirth.Text = empl.BirthDate.Value.ToShortDateString();
}
else
{
Load();
}
}
}
所以我必须遍历这个集合,但是当我到达集合的末尾时,我得到这个异常。有人能告诉我为什么我的if区块不会停止那种异常吗?由于'System.ArgumentOutOfRangeException'
您应该递增'currentIndex'的值,然后检查它是否小于'ctx.Employees.Count()' – Nasreddine