3 回答

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

TA貢獻(xiàn)1852條經(jīng)驗(yàn) 獲得超7個(gè)贊
想要過(guò)濾列表以獲取分?jǐn)?shù)為 0 且按團(tuán)隊(duì)名稱分組的電子郵件 ID。
過(guò)濾列表以獲取分?jǐn)?shù)為 0 的電子郵件 ID
var filteredList = list.Where(record => records.Score == 0);
按團(tuán)隊(duì)名稱分組
var groupedByTeamName = filteredList.GroupBy(record => record.Team)
IEnumerable<IGrouping<TRecord, TTeam>>
如果我沒(méi)記錯(cuò)的話,這將返回一個(gè)。IGrouping<T,K>
只是一個(gè)列表,其中包含Key
包含您分組依據(jù)的屬性(在本例中為團(tuán)隊(duì))。
您當(dāng)然可以以級(jí)聯(lián)方式調(diào)用它們:
list.Where(record => records.Score == 0).GroupBy(record => record.Team);
但是調(diào)試會(huì)有點(diǎn)困難,因?yàn)槟仨氝x擇代碼并快速監(jiān)視句子的部分。有時(shí)這不起作用。

TA貢獻(xiàn)2065條經(jīng)驗(yàn) 獲得超14個(gè)贊
想要過(guò)濾列表以獲取分?jǐn)?shù)為 0 且按團(tuán)隊(duì)名稱分組的電子郵件 ID。
這是一個(gè)很難說(shuō)的方式嗎:
我想要未得分團(tuán)隊(duì)成員的所有電子郵件嗎?
將您的數(shù)據(jù)分組為“球隊(duì)及其球員和得分”;僅保留那些得分為零的球隊(duì)并提取球員的電子郵件。
為此,我們使用帶有 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 關(guān)注
- 166 瀏覽
添加回答
舉報(bào)