我正在尝试检查我的集合中的所有项目是否都有特定的属性值,假设我有一个名为的属性IsFavourite,我需要检查每个元素的属性是否为真.我试过这个:
var c = listView.Items.Cast<Event>().Where(x => x.MatchNation == nation
&& x.MatchLeague == league && x.IsFavourite == true).Any();
Run Code Online (Sandbox Code Playgroud)
但这只会返回一个具有此属性的项目.
你必须使用 All()
bool result = listView.Items.Cast<Event>()
.Where(x => x.MatchNation == nation && x.MatchLeague == league)
.All(x => x.IsFavourite);
Run Code Online (Sandbox Code Playgroud)