c# - Can I use the .Min() Linq extension method on a bool type? -
i want find if have bools false in collection. can use following code find it?
this.mylist.min(e => e.mybool)
i'm hoping return false if there false in collection.
you can use (renamed collection reasons of readability):
bool anyfalse = mybools.any(b => !b);
or
bool anyfalse = !mybools.all(b => b);
both efficient since break on first false
.
if there complex objects in collection(as seerms be) use:
bool anyfalse = mylist.any(x => !x.mybool);
or
bool anyfalse = !mylist.all(x => x.mybool);
Comments
Post a Comment