if condition with nullable

前端 未结 10 1133
抹茶落季
抹茶落季 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 10:53

    It's the most obvious usage for Nullable

    Be careful with statements like that. What seem obvious to you isn't necessarily what is obvious for some one else.

    Furthermore,

    if(x) {}
    

    would also be illegal in case x was a reference type, so in the interest of consistency, the behavior should be the same for Nullables.

提交回复
热议问题