I need to check unknown number of booleans.. depending on the result it will do the appropriate function. Here is example of what I'm searching:
if(bool[x] && bool[y] && bool[z] ...)
myFunc();
I need to check unknown number of booleans.. depending on the result it will do the appropriate function. Here is example of what I'm searching:
if(bool[x] && bool[y] && bool[z] ...)
myFunc();
Something like this:
var all=true;
for (var i=x; i<z; i++) if (!bool[i]) {all=false; break;}
if (all) myFunc()
or, if x, y, z
are not sequential, put them in the list or array:
int[] indices = new [] {x, y, z};
and then iterate like this:
var all=true;
foreach (var i in indices) if (!bool[i]) {all=false; break;}
if (all) myFunc()
You can use
LINQ
for that.If you need all the bools to be true, you can use
Any
:If you need, for example, 4 of them exactly to be true, you can use
Count
:Or at least one, there's
Any