I’m looking at someone’s code and they did:
if ( myNum > (num1 && num2 && num3) )
… with the intent of executing code when myNum is greater than num1, num2, and num3. Will this work?
edit: Thanks guys. I didn’t think it would work, but I’m no expert, so I thought I’d ask people who are.
No – certainly not in C# or Java, at least. You want:
(It’s possible that you don’t need the brackets here – I can never remember operator precedence.)
It wouldn’t work as written in Java or C# as
&&is an operator on Boolean operands, with a Boolean result. It’s possible that it would compile/run in a less strongly-typed language, but I highly doubt that it will have the intended effect in any mainstream language.