Why does C# && and || operators work the way they do?

前端 未结 7 2000
余生分开走
余生分开走 2020-12-06 14:25

here is a tl;dr

I come from a C++ background. && is suppose to check if left side is true and right side is true. what does & have anything to do with th

7条回答
  •  不知归路
    2020-12-06 14:43

    If x == false, then x && y will be always false -> no need to see value of y. If x == true, then x & y happens. This gives you optimized logic operations.

    For int it will be something like: T.false(x == true) ? x : T.&(x == true, y == true)

提交回复
热议问题