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         }

输出

C# ??符号

相关文章:

  • 2022-02-10
  • 2022-12-23
  • 2021-08-17
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2022-03-09
  • 2021-09-04
  • 2022-03-04
  • 2022-01-02
  • 2021-11-29
  • 2021-08-03
  • 2021-12-23
相关资源
相似解决方案