Why '&&' and not '&'?

前端 未结 16 1561
别跟我提以往
别跟我提以往 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:58

    if (list.Count() > 14 && list[14] == "foo")
    

    is safe

    if (list.Count() > 14 & list[14] == "foo")
    

    would crash if the list doesn't have the right size.

提交回复
热议问题