C# ?方法,再也不用string.IsNullOrEmpty
传统做法:
判断字符串是否为空,写法繁琐:
if(string.IsNullOrEmpty(s1))
{
// .....
}
现代方法
string result = s2?.ToString() ?? "";
或 string result = s2?.ToString() ;
解释:
s2?.ToString() 如果s2为null,则直接返回s2
s2?.ToString() ?? ""; 如果s2为null,则返回""