我们一直在工作中进入不必要的编码论证.今天我询问条件AND(&&)或OR(||)是否具有更高的优先级.我的一个同事坚持认为他们有同样的优先权,我有疑虑,所以我查了一下.
根据MSDN AND(&&)具有比OR(||)更高的优先级.但是,你能向持怀疑态度的同事证明这一点吗?
http://msdn.microsoft.com/en-us/library/aa691323(VS.71).aspx
bool result = false || true && false; // --> false
// is the same result as
bool result = (false || true) && false; // --> false
// even though I know that the first statement is evaluated as
bool result = false || (true && false); // --> false
Run Code Online (Sandbox Code Playgroud)
所以我的问题是你如何用代码证明AND(&&)的优先级高于OR(||)?如果你的答案无关紧要,那么为什么用这种语言建立?
c# conditional conditional-operator operator-precedence associativity