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

前端 未结 7 1987
余生分开走
余生分开走 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条回答
  •  -上瘾入骨i
    2020-12-06 14:46

    These operators become easier to understand if you translate them into VB.Net, as follows:

    && = AndAlso: IF foo IsNot Nothing AndAlso foo.bar=1 then <>...

    || = OrElse: If foo Is Nothing OrElse foo.bar=0 then ...<>...

    That way when you read them in English you really get the idea of what they are trying to acheive.

提交回复
热议问题