亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

將 lambda 表達式轉換為 linq c#

將 lambda 表達式轉換為 linq c#

C#
HUWWW 2021-06-24 18:19:34
我有學生名單和講師名單,我用雙 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;


查看完整回答
反對 回復 2021-06-27
  • 2 回答
  • 0 關注
  • 167 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號