3 回答

TA貢獻1853條經驗 獲得超6個贊
不確定你現在在做什么,但這就是我會做的
var result = list.Where(p => p.Score == 0) .Select(p => new{p.Team, p.EmailId}) .GroupBy(p => p.Team) .Distinct();

TA貢獻1852條經驗 獲得超7個贊
想要過濾列表以獲取分數為 0 且按團隊名稱分組的電子郵件 ID。
過濾列表以獲取分數為 0 的電子郵件 ID
var filteredList = list.Where(record => records.Score == 0);
按團隊名稱分組
var groupedByTeamName = filteredList.GroupBy(record => record.Team)
IEnumerable<IGrouping<TRecord, TTeam>>
如果我沒記錯的話,這將返回一個。IGrouping<T,K>
只是一個列表,其中包含Key
包含您分組依據的屬性(在本例中為團隊)。
您當然可以以級聯方式調用它們:
list.Where(record => records.Score == 0).GroupBy(record => record.Team);
但是調試會有點困難,因為您必須選擇代碼并快速監視句子的部分。有時這不起作用。

TA貢獻2065條經驗 獲得超14個贊
想要過濾列表以獲取分數為 0 且按團隊名稱分組的電子郵件 ID。
這是一個很難說的方式嗎:
我想要未得分團隊成員的所有電子郵件嗎?
將您的數據分組為“球隊及其球員和得分”;僅保留那些得分為零的球隊并提取球員的電子郵件。
為此,我們使用帶有 aKeySelector 和 aResultSelector 的 GroupBy 重載
var emailsOfPlayersInTeamsWithZeroScor = myInput.GroupBy
? ? // keySelector: the team
? ? .GroupBy(inputItem => inputItem.Team,
? ? // ResultSelector: from every Team with its players and scores
? ? // make sequences of emails of players and check if there is a score at all
? ? (team, players) => new
? ? {
? ? ? ? // not interested in the team
? ? ? ? // remember if all scores are zero
? ? ? ? HasOnlyZeroScore = players.All(player.Score == 0),
? ? ? ? // remember all emails of the players in the team
? ? ? ? PlayerEmails = players.Select(player => player.Email),
? ? })
? ? // keep only the items with a zero score
? ? .Where(team => team.HasOnlyZeroScore)
? ? // and select the lists of emails per team as one big list:
? ? .SelectMany(team => team.PlayerEmails);
- 3 回答
- 0 關注
- 167 瀏覽
添加回答
舉報