3 回答

TA貢獻(xiàn)2016條經(jīng)驗(yàn) 獲得超9個贊
查詢語法中沒有與 Any 等效的內(nèi)容。所以你能做的最好的事情是:
IEnumerable<Gruppe> cand =
from population in populations
where !population.Attributes.Any(y => y.GetType() == typeof(Arbeit))
select population
(我假設(shè)沒有必要強(qiáng)制轉(zhuǎn)換為 IEnumerable<Gruppe>。如果該假設(shè)錯誤,您需要將其添加回來。)

TA貢獻(xiàn)1805條經(jīng)驗(yàn) 獲得超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

TA貢獻(xiàn)1809條經(jīng)驗(yàn) 獲得超8個贊
Any 可以重構(gòu),但您仍然需要 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;
- 3 回答
- 0 關(guān)注
- 252 瀏覽
添加回答
舉報(bào)