Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Linq : How do I test a List<bool> for condition where any one of its values == true?

Tags:

linq

I have a list,

List<bool> MyList;
MyList.Add(true);
MyList.Add(false);
MyList.Add(false);

What is a clean way to use linq to test if any value is true? I tried

MyList.Find(SomeBoolean=>SomeBoolean)

but the result is weird.

like image 718
black eyed pea Avatar asked Feb 07 '13 07:02

black eyed pea


1 Answers

Try :

bool test = MyList.Any(x => x);

But you have to initialize your list before inserting anything.

like image 57
xlecoustillier Avatar answered Nov 03 '22 01:11

xlecoustillier