A clear, layman's explanation of the difference between | and || in c#?

后端 未结 11 533
余生分开走
余生分开走 2020-12-02 12:51

Ok, so I\'ve read about this a number of times, but I\'m yet to hear a clear, easy to understand (and memorable) way to learn the difference between:

if (x |         


        
11条回答
  •  -上瘾入骨i
    2020-12-02 13:34

    Without delving into the details in any way, shape, or form, here's a real layman's version.

    Think of "|" as a straight "or" in english; think of "||" as "or else" in english.

    Similarly think of "&" as "and" in english; think of "&&" as "and also" in english.

    If you read an expression to yourself using these terms, they often make a lot more sense.

提交回复
热议问题