-3
嗨我有以下代码,用于在添加学生后从列表中搜索学生ID。我第一次获取它时,它正常工作,但是当我添加另一个学生并搜索该特定ID时,我找不到它。有人能告诉我哪里错了吗?没有从列表中获取一些项目
public void AddMarks(int id)
{
for (int i = 0; i < mystudent.Count; i++)
{
if (mystudent[i].Id == id)
{
foreach (Student st in mystudent)
{
Console.WriteLine("enter Mathematics halfyearly exam");
Maths.HYEXAM = Int16.Parse(Console.ReadLine());
Console.WriteLine("enter Mathematics annualyear exam");
Maths.ANEXAM = Int16.Parse(Console.ReadLine());
}
}
}
}
你的代码没有意义:为什么你遍历列表两次?数学是什么,你可能是指圣玛斯? – BlackBear
调试器告诉你什么 – pm100