I have an array of booleans which gets filled by a loop. The method that owns the array needs to return a single boolean. So can I do this:
bool[] Booleans = new bool[4];
// do work - fill array
return (Booleans[0] && Booleans[1] && Booleans[2] && Booleans[3]);
So if I have: T,T,F,T will I get F back since there is one in the array or will it send back something else or just crash all together?
A single
falsewill result infalsebeing returned with booleanANDlogic.You can also rewrite as:
For the sake of completeness, or if LINQ is not an option, you can achieve the same via a loop:
For small samples what you have is fine, but as the number of items grow either of the above approaches will make the code a lot friendlier.