C#总是有些讨人喜欢的写法,即简洁又不会引起混乱。??运算符就是这样。为了确保赋值不为空,我们通常这样写:

1:  string name = null;
2:  string str = (name == null) ? "" : name;

 
有了??运算符,我们就有了更简洁的写法:

1:  string name = null;
2:  string str = name ?? "";

 

是不是很清爽?我用了好几年了,却是头一回看到,真是相见恨晚。