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

前端 未结 8 2073
遥遥无期
遥遥无期 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 19:02

    Since by default an int cannot be null and its value will be set to 0, the operator of > and < which is built for int type, expects to work with values and not with nulls.

    see my answer to a similar question where I wrote some ways to handle nullable int with the less < and greater > operators https://stackoverflow.com/a/51507612/7003760

提交回复
热议问题