- Hands-On Object:Oriented Programming with C#
- Raihan Taher
- 114字
- 2021-07-02 12:44:34
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.
推薦閱讀
- ClickHouse性能之巔:從架構(gòu)設(shè)計解讀性能之謎
- JavaScript百煉成仙
- Java Web開發(fā)之道
- 64位匯編語言的編程藝術(shù)
- C語言程序設(shè)計
- Teaching with Google Classroom
- 搞定J2EE:Struts+Spring+Hibernate整合詳解與典型案例
- 深入理解C指針
- Clean Code in C#
- Practical Microservices
- C++程序設(shè)計教程
- Android Studio開發(fā)實戰(zhàn):從零基礎(chǔ)到App上線 (移動開發(fā)叢書)
- Go語言入門經(jīng)典
- 趣學(xué)數(shù)據(jù)結(jié)構(gòu)
- Mastering Vim