//1、可空类型修饰符(?),如:
A ?? B//表示如果A为null则返回B,否则返回A
//2、三元运算符(?,如:
bool f=false; return f==true?1:0;//如果f为true则返回1,否则返回0
//3、 空合并运算符(??)如:
a??b //当a为null时则返回b,a不为null时则返回a本身
“a??b??c”的形式按“a??(b??c)”计算
//4、NULL检查运算符(?.)
fileInfo?.Close() //当fileInfo不为null是执行Close方法
DateTime? birthday= personList?.FirstOrDefault()?.Birthday;
c#中“?“的几种用法
最新推荐文章于 2023-06-20 17:54:08 发布