当前位置: 代码迷 >> C# >> C# ?符号
  详细解决方案

C# ?符号

热度:538   发布时间:2016-04-28 08:29:49.0
C# ??符号

 

 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=strA10              */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         }

输出

  相关解决方案