I have three boolean variables. I need to check if all three are true or all three are false.
I can do this in a 'dummy' way:
bool areSame = false;
if(a && b && c)
areSame = true;
else if (!a && !b && !c)
areSame = true;
I'd like to know if there is another more elegant solution.
You can use the equality operator on booleans too:
bool areSame = (a == b) && (a == c);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With