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 check if any value is true? I tried
MyList.Find(SomeBoolean=>SomeBoolean)
but the result is strange.
Try:
bool test = MyList.Any(x => x);
But you must initialize your list before inserting anything.
Use any
var anyTrue = MyList.Any(i => i);
true
List<bool> MyList = new List<bool>(); MyList.Add(true); MyList.Add(false); MyList.Add(false); var listTrue = MyList.Where(c => c);
, Class, .Find, .
Class
.Find
var b = MyList.Find(c => c)
, var DataType?
var
DataType
myList - bool
myList = getSelectedChannels(); allTrue = myList.FindAll(a = > a == true);
allTrue bool, (bool - true). allTrue.Count, .