1 static void Main(string[] args) 2 { 3 string strA = String.Empty; 4 string strB = String.Empty; 5 strA = null; 6 strB = "strB"; 7 /** 8 * 如果??左边的strA值为String.IsNullOrWhiteSpace则StrC=strB 9 * 如果??右边的strB值为String.IsNullOrWhiteSpace则StrC=strA 10 */ 11 string StrC = strA ?? strB; 12 Console.WriteLine(StrC); 13 14 strB = null; 15 strA = "strA"; 16 Console.WriteLine(strA ?? strB); 17 18 strB = String.Empty; 19 strA = "No Empty"; 20 string a = strA ?? strB; 21 Console.WriteLine(a == null ? "null" : a); 22 Console.ReadLine(); 23 }
输出