当前位置:网站首页>C#中?的这种形式
C#中?的这种形式
2022-04-23 05:46:00 【OceanKeeper1215】
1.可空类型修饰符(?)
引证类型能够运用空引证表明一个不存在的值,而值类型通常不能表明为空。
例如:stringstr=null;是正确的,inti=null;编译器就会报错。
为了使值类型也可为空,就能够运用可空类型,即用可空类型修饰符"?"来表明,表现方式为"T?"
例如:int?表明可空的整形,DateTime?表明可为空的时刻。
T?其实是System.Nullable(泛型结构)的缩写方式,
也就意味着当你用到T?时编译器编译时会把T?编译成System.Nullable的方式。
例如:int?,编译后就是System.Nullable的方式。
2.三元(运算符)表达式(?:)
例如:x?y:z表明假如表达式x为true,则回来y;
假如x为false,则回来z,是省掉if{}else{}的简单方式。
3.空兼并运算符(??)
用于定义可空类型和引证类型的默认值。
假如此运算符的左操作数不为null,则此运算符将回来左操作数,否则回来右操作数。
例如:a??b当a为null时则回来b,a不为null时则回来a自身。
空兼并运算符为右结合运算符,即操作时从右向左进行组合的。
如,“a??b??c”的方式按“a??(b??c)”计算。
4.NULL查看运算符(?.)
版权声明
本文为[OceanKeeper1215]所创,转载请带上原文链接,感谢
https://blog.csdn.net/OceanKeeper1215/article/details/122040868
边栏推荐
- 日志
- Calculation (enter the calculation formula to get the result)
- MySQL groups are sorted by a field, and the first value is taken
- POI and easyexcel exercises
- 破解滑动验证码
- 基于pygame库编写的五子棋游戏
- 爬西瓜视频url
- 解决ArcGIS分区统计显示太多唯一值执行失败
- Integration and induction of knowledge points of automatic control principle (Han min version)
- 电机与拖动(戚金清版)学习整理
猜你喜欢
Robocode教程4——Robocode的游戏物理
Addition, deletion, query and modification of data
Explanation of login page
自动控制原理知识点整合归纳(韩敏版)
檢測技術與原理
Rust的闭包类型(Fn, FnMut, FnOne的区别)
Techniques et principes de détection
检测技术与原理
1007 go running (hdu6808) in the fourth game of 2020 Hangzhou Electric Multi school competition
[untitled] database - limit the number of returned rows
随机推荐
Conversion between JS object and string
爬虫效率提升方法
Robocode教程4——Robocode的游戏物理
批量导出Arcgis属性表
[leetcode 67] sum of two binary numbers
用C语言实现重写strcmp等四个函数
Linux 用rpm的方式安装mysql(超简单)
斯坦福机器学习课程汇总
Object转Json差异之Gson fastJson jackson 修改字段名
[leetcode169] most elements
Guaba and Computational Geometry
Definition of C class and method
安装pyshp库
Customized communication between threads (reentrantlock)
Cf6d lizards and fundamentals 2 problem solving
爬取彩票数据
serde - rust的序列化方案
Export of data
爬取蝉妈妈数据平台商品数据
Rust的闭包类型(Fn, FnMut, FnOne的区别)