我想检查我的集合中的所有项目是否具有特定的属性值,假设我有一个名为IsFavourite
的属性,我需要检查这个属性对于每个元素是否为true。我试过这个:如何检查集合中的所有项目是否具有特定的属性值?
var c = listView.Items.Cast<Event>().Where(x => x.MatchNation == nation
&& x.MatchLeague == league && x.IsFavourite == true).Any();
但是这只会返回一个具有此属性的项目。
将'Any()'改为'All()',你也不需要'== true',你可以简单地写'&& x.IsFavourite'。 –
只需使用'All'而不是'Any'。 – Mormegil