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

前端 未结 8 2201
盖世英雄少女心
盖世英雄少女心 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:05

    Nullable Types

    Nullable types are instances of the System.Nullable struct. A nullable type can represent the normal range of values for its underlying value type, plus an additional null value. For example, a [Nullable], pronounced "Nullable of Int32," can be assigned any value from -2147483648 to 2147483647, or it can be assigned the null value. A [Nullable] can be assigned the values true or false, or null. The ability to assign null to numeric and Boolean types is particularly useful when dealing with databases and other data types containing elements that may not be assigned a value. For example, a Boolean field in a database can store the values true or false, or it may be undefined.

提交回复
热议问题