C# conditional AND (&&) OR (||) precedence

前端 未结 1 559
清歌不尽
清歌不尽 2020-11-28 07:23

We get into unnecessary coding arguments at my work all-the-time. Today I asked if conditional AND (&&) or OR (||) had higher precedence. One of my coworkers insiste

相关标签:
1条回答
  • 2020-11-28 07:51

    Change the first false by true. I know it seems stupid to have (true || true) but it proves your point.

    bool result = true || true && false;   // --> true 
         result = (true || true) && false; // --> false
         result = true || (true && false); // --> true
    
    0 讨论(0)
提交回复
热议问题