Why '&&' and not '&'?

前端 未结 16 1518
别跟我提以往
别跟我提以往 2020-11-27 12:11

Why is && preferable to & and || preferable to |?

I asked someone who\'s been programming for years a

16条回答
  •  粉色の甜心
    2020-11-27 12:57

    In the case of:

    if (obj != null && obj.Property == true) { }
    

    would work as expected.

    But:

    if (obj != null & obj.Property == true) { }
    

    could potentially throw a null reference exception.

提交回复
热议问题