所以我有这个代码,问题是,在我的项目中,它必须用 linq 表达式编写,我不知道如何做到这一点,因为有两个列表。有任何想法吗?
public void GetLecturersWorkloadStatistics(List<Student> studentList, List<Lecturer> lecturerList)
{
foreach (Lecturer lecturer in lecturerList)
{
foreach (Student student in studentList)
{
if (lecturer.ModuleName == student.ModuleName &&
lecturer.LastName == student.LecturerLastName &&
lecturer.FirstName == student.LecturerFirstName)
{
lecturer.Credits = lecturer.Credits + lecturer.ModuleValueInCredits;
}
}
}
}
如上所述,我已经用 linq 完成了内部操作,但我不知道下一步该做什么。
public void GetLecturersWorkloadStatistics(List<Student> studentList, List<Lecturer> lecturerList)
{
foreach (Lecturer lecturer in lecturerList)
{
studentList = (from student in studentList
where lecturer.ModuleName == student.ModuleName &&
lecturer.LastName == student.LecturerLastName &&
lecturer.FirstName == student.LecturerFirstName
select student).ToList();
}
}
隔江千里
慕雪6442864
哆啦的时光机
相关分类