What is the purpose of a question mark after a type (for example: int? myVariable)?

前端 未结 8 2202
盖世英雄少女心
盖世英雄少女心 2020-11-22 10:26

Typically the main use of the question mark is for the conditional, x ? \"yes\" : \"no\".

But I have seen another use for it but can\'t find an explanat

8条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2020-11-22 11:09

    In

    x ? "yes" : "no"
    

    the ? declares an if sentence. Here: x represents the boolean condition; The part before the : is the then sentence and the part after is the else sentence.

    In, for example,

    int?
    

    the ? declares a nullable type, and means that the type before it may have a null value.

提交回复
热议问题