why this is true:
(true | false & false)
and this is false:
(true | false && false)
in my mind should be the oposite..
why this is true:
(true | false & false)
and this is false:
(true | false && false)
in my mind should be the oposite..
They bind as:
true | (false & false) // true
and
(true | false) && false // false
I would avoid writing code which relies on these rules though - it's obviously unclear to the reader :)
For reference, see section 7.3.1 of the C# 4 language specification, which shows &
having higher precedence than |
(hence the first result) and |
having higher precedence than &&
(hence the second result).
&
has priority to |
which has priority to &&
, so your expressions are evaluated as
(true | (false & false)) = (true | false) = true
and
((true | false) && false) = (true && false) = false
See the reference of C# operators containing there precedence for more information.