if condition with nullable

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

    Consider what whould happen in this case then

    bool? nullBool = null;
    if (nullBool)
    {
        someCode();
    }
    

    It would be impossible to tell if it entered the if senctence because the bool was null or false. That is probably not desirable

提交回复
热议问题