Why does >= return false when == returns true for null values?

前端 未结 8 2053
遥遥无期
遥遥无期 2020-12-07 18:17

I have two variables of type int? (or Nullable if you will). I wanted to do a greater-than-or-equal (>=) comparison on the two variables but as it turns out, this

8条回答
  •  無奈伤痛
    2020-12-07 18:56

    Because Equality is defined separately from Comparability.
    You can test x == null but x > null is meaningless. In C# it will always be false.

提交回复
热议问题