[removed] What is the difference between `if (!x)` and `if (x == null)`?

后端 未结 6 2040
遥遥无期
遥遥无期 2020-12-08 05:18

What is the difference between if (!x) and if (x == null); that is, when can their results be different?

6条回答
  •  半阙折子戏
    2020-12-08 06:12

    !x tests for a false value. This will be true for any value that can propagate to false for whatever reason. This will be true for permutations of false, 0, etc etc.

    x == null is different because var x = 0 will NOT be null... but WILL be false.

提交回复
热议问题