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