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

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

Linq:如何在查詢語法中編寫 Any ?

Linq:如何在查詢語法中編寫 Any ?

C#
弒天下 2023-12-17 09:57:34
IEnumerable<Gruppe> cand = (IEnumerable<Gruppe>)populations.Where(                             x => !x.Attributes.Any(                                  y => y.GetType() == typeof(Arbeit)                               )                           );我想知道如何用查詢語法編寫上述內容,但由于 Any 方法而被絆倒。
查看完整描述

3 回答

?
慕沐林林

TA貢獻2016條經驗 獲得超9個贊

查詢語法中沒有與 Any 等效的內容。所以你能做的最好的事情是:


IEnumerable<Gruppe> cand =

   from population in populations

   where !population.Attributes.Any(y => y.GetType() == typeof(Arbeit))

   select population

(我假設沒有必要強制轉換為 IEnumerable<Gruppe>。如果該假設錯誤,您需要將其添加回來。)


查看完整回答
反對 回復 2023-12-17
?
holdtom

TA貢獻1805條經驗 獲得超10個贊

我喜歡斯維克的回答。


另一種說法是這樣的:


IEnumerable<Gruppe> cand = 

    from population in populations

    where ( from attribute in population.Attributes

        where attribute.GetType() == typeof(Arbeit)

        select true).Any() == false

    select population


查看完整回答
反對 回復 2023-12-17
?
海綿寶寶撒

TA貢獻1809條經驗 獲得超8個贊

Any 可以重構,但您仍然需要 Count。


var cand = from population in populations

           let attributeCount = population.Attributes.Count

           let validAttributeCount = (

               from attribute in population.Attributes

               where attribute.GetType() != typeof(Arbeit)

               select attribute

           ).Count()

           where attributeCount == validAttributeCount

           select population;


查看完整回答
反對 回復 2023-12-17
  • 3 回答
  • 0 關注
  • 260 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

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

幫助反饋 APP下載

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

公眾號

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