官术网_书友最值得收藏!

Nullable types

The primitive types or value types are not nullable in C#. Consequently, there is always a requirement for the developer to make the type nullable, as a developer might need to identify whether the value is provided explicitly or not. The newest version of .NET provides nullable types:

Nullable<int> a = null;
int? b = a; //same as above

Both lines in the preceding example define the nullable variable, while the second line is just a shortcut of the first declaration. When the value is null, the HasValue property will return false. This will ensure that you can detect whether the variable is explicitly specified as a value or not.

主站蜘蛛池模板: 枣强县| 措美县| 钟祥市| 时尚| 稷山县| 巴林左旗| 石渠县| 六枝特区| 陆丰市| 沅江市| 手游| 方山县| 分宜县| 新田县| 略阳县| 黄龙县| 天祝| 双峰县| 天等县| 潜江市| 滁州市| 苍山县| 蒙自县| 孟津县| 新巴尔虎右旗| 蒲城县| 文昌市| 盈江县| 南阳市| 垣曲县| 富平县| 平乡县| 安塞县| 饶平县| 藁城市| 武邑县| 平顶山市| 白山市| 通榆县| 阳城县| 额尔古纳市|