我有學生名單和講師名單,我用雙 foreach 語句編寫了代碼。有沒有辦法使用 Lambda 表達式來簡化此代碼?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; } } }}
2 回答

炎炎設計
TA貢獻1808條經驗 獲得超4個贊
這與您的問題的輸出完全相同,僅使用 lambda 表達式。
studentListBySelectedLecturer = (from stud in linkedList
where stud.LecturerFirstName == lecturerInformation[0] &&
stud.LecturerLastName == lecturerInformation[1] ||
stud.LecturerFirstName == lecturerInformation[1] &&
stud.LecturerLastName == lecturerInformation[0]
select stud).ToList();
return studentListBySelectedLecturer;
- 2 回答
- 0 關注
- 167 瀏覽
添加回答
舉報
0/150
提交
取消