How does comparison operator works with null int?

前端 未结 4 527
半阙折子戏
半阙折子戏 2020-11-27 04:48

I am starting to learn nullable types and ran into following behavior.

While trying nullable int, i see comparison operator gives me unexpected result. For example,

4条回答
  •  轮回少年
    2020-11-27 04:56

    According to MSDN - it's down the page in the "Operators" section:

    When you perform comparisons with nullable types, if the value of one of the nullable types is null and the other is not, all comparisons evaluate to false except for !=

    So both a > b and a < b evaluate to false since a is null...

提交回复
热议问题