if condition with nullable

前端 未结 10 1138
抹茶落季
抹茶落季 2021-01-02 10:20

There is a lot of syntax sugar with Nullable like those:

int? parsed to Nullable

int? x = null
   if (x != null) // Parsed          


        
10条回答
  •  死守一世寂寞
    2021-01-02 11:13

    It's not that obvious that null should mean false. A null value means that the value is unknown or uninitialized. It's unknown whether the value is true or false. Who said null should behave like false?

    A more obvious usage for Nullable is to store something that can be either true or false, but sometimes is irrelevant or unknown, in which case the value is null.

提交回复
热议问题