第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問(wèn)題,去搜搜看,總會(huì)有你想問(wèn)的

Linq 過(guò)濾器以避免循環(huán)

Linq 過(guò)濾器以避免循環(huán)

C#
海綿寶寶撒 2023-07-09 10:28:45
我正在嘗試制定 LINQ 查詢,但不是專業(yè)人士,所以無(wú)論我嘗試什么都不起作用。我想過(guò)濾列表以從下面的列表中獲取電子郵件 ID,其中分?jǐn)?shù)為 0,并按團(tuán)隊(duì)名稱分組。我嘗試這樣做的方式是:獲取不同團(tuán)隊(duì)名稱的列表。循環(huán)遍歷每個(gè)不同的團(tuán)隊(duì)名稱并獲取分?jǐn)?shù)為 0 的電子郵件 ID。Team    Name   Score    EmailId   Hawk    Amy     0       Amy@gmail.com   Hawk    Aby     0       Aby@gmail.com   Hawk    Raf     1       Raf@gmail.com   Hawk    Jay     2       Jay@gmail.com   Eagle   Blu     0       Blu@gmail.com   Eagle   Tru     1       Tru@gmail.com我想得到兩行:Hawkand Amy@gmail.com, Aby@gmail.com,下一個(gè)結(jié)果是Eaglewith Blue@gmail.com。 這可以通過(guò) LINQ 一步完成嗎?
查看完整描述

3 回答

?
墨色風(fēng)雨

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();


查看完整回答
反對(duì) 回復(fù) 2023-07-09
?
慕姐4208626

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í)這不起作用。


查看完整回答
反對(duì) 回復(fù) 2023-07-09
?
翻翻過(guò)去那場(chǎng)雪

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);


查看完整回答
反對(duì) 回復(fù) 2023-07-09
  • 3 回答
  • 0 關(guān)注
  • 166 瀏覽

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購(gòu)課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)