您的位置:首页 > 编程语言 > C#

C# ??符号

2015-11-27 14:52 447 查看
static void Main(string[] args)
{
string strA = String.Empty;
string strB = String.Empty;
strA = null;
strB = "strB";
/**
* 如果??左边的strA值为String.IsNullOrWhiteSpace则StrC=strB
* 如果??右边的strB值为String.IsNullOrWhiteSpace则StrC=strA
*/
string StrC = strA ?? strB;
Console.WriteLine(StrC);

strB = null;
strA = "strA";
Console.WriteLine(strA ?? strB);

strB = String.Empty;
strA = "No Empty";
string a = strA ?? strB;
Console.WriteLine(a == null ? "null" : a);
Console.ReadLine();
}


输出

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: