当前位置:网站首页>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
边栏推荐
猜你喜欢
随机推荐
Completely clean up MySQL win
基于QQwebAPI 查询昵称和头像的爬虫
[leetcode217] there are duplicate elements
爬取手游网站游戏详情和评论(MQ+多线程)
多线程爬取马可波罗网供应商数据
Feign请求日志统一打印
安全授信
-- SQL query and return limit rows
Installation and usage skills of idea
爬虫效率提升方法
Explanation of the second I interval of 2020 Niuke summer multi school training camp
[leetcode 54] spiral matrix
Conversion between JS object and string
Cf6d lizards and fundamentals 2 problem solving
Detection technology and principle
Record the installation and configuration of gestermer on TX2, and then use GST RTSP server
SQL -- data filtering and grouping
解决ArcGIS分区统计显示太多唯一值执行失败
[untitled] database - limit the number of returned rows
Cf515b drazil and his happy friends

![[leetcode 59] spiral matrix II](/img/6e/58e600272797563129d2b325a054b5.png)






