- 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.
推薦閱讀
- Game Programming Using Qt Beginner's Guide
- AWS Serverless架構(gòu):使用AWS從傳統(tǒng)部署方式向Serverless架構(gòu)遷移
- 深度強(qiáng)化學(xué)習(xí)算法與實(shí)踐:基于PyTorch的實(shí)現(xiàn)
- Spring Boot企業(yè)級(jí)項(xiàng)目開(kāi)發(fā)實(shí)戰(zhàn)
- Node.js全程實(shí)例
- Cybersecurity Attacks:Red Team Strategies
- 圖數(shù)據(jù)庫(kù)實(shí)戰(zhàn)
- ASP.NET程序開(kāi)發(fā)范例寶典
- Python:Deeper Insights into Machine Learning
- TypeScript圖形渲染實(shí)戰(zhàn):2D架構(gòu)設(shè)計(jì)與實(shí)現(xiàn)
- Instant GLEW
- RESTful Web API Design with Node.js
- Zend Framework 2 Cookbook
- Learning jqPlot
- Advanced C++