首页 > Windows开发 > 详细

C# ??符号

时间:2015-11-27 16:55:43      阅读:309      评论:0      收藏:0      [点我收藏+]

 

 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# ??符号

原文:http://www.cnblogs.com/yf2011/p/5000669.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!