null操作符
C#提供了两种操作符 ,它们可以更容易的处理null
null合并操作符 ??
string s1 = "something";//合并操作符
string s2 = s1 ?? "nothing";//意思就是把s1传给s2,s2不为空的话,就返回s2的值,否则返回"nothing"
Console.WriteLine(s2);
null条件操作符
//x ?. y ?. z
//x == null ? null 如果x不等于null返回右边表达式
//如果x = null 则返回 null 第一行和第二行意思一样,第二行相当于简化表达式
//也可以两种一起合并使用