Álvaro García
Álvaro García

Reputation: 19356

How to check if all that is equal to A has property B to true?

I have a class Person with two properties, genre and IsDead. I want to know if all men are death or not, in a list.

I am using this way:

if(myList.Where(x=> x.Genre == "MALE").All(x=> x.IsDeath == true));

But I don't know if there are other better option, instead of using a where and set all the properties in the All, Any... function.

Thanks.

Upvotes: 0

Views: 87

Answers (1)

ElectricRouge
ElectricRouge

Reputation: 1279

You can also do.

if(!myList.Any(x => x.Genre == "MALE" && !x.IsDeath))

Upvotes: 2

Related Questions