using System;
using System.Collections.Generic;
using System.Text;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
string a = "test1";
string b = null;
string c = a ?? "test2";
string d = b ?? "test3";
Console.WriteLine("a:{0} b:{1} c:{2}, d:{3}", a, b, c, d);
Console.ReadLine();
}
}
}
程序应该输出什么呢?
这个"??"运算符我是在CommunityServer里面看到的,在里面大量的使用这个运算符 ,当时还看的莫名其妙 ,好像"? : "这个三元运算符.
不过它完成的功能确实和"? : "相似 ,只是在特定条件下更简洁了.
输出的内容是这个:
a:test1 b: c:test1, d:test3
补充一下:
??左边的内容如果不为空则返回左值的内容,如果为空则返回右值的内容。
不过这个符号貌似不常用,或者基本没看到什么人用,毕竟不广泛
using System.Collections.Generic;
using System.Text;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
string a = "test1";
string b = null;
string c = a ?? "test2";
string d = b ?? "test3";
Console.WriteLine("a:{0} b:{1} c:{2}, d:{3}", a, b, c, d);
Console.ReadLine();
}
}
}
程序应该输出什么呢?
这个"??"运算符我是在CommunityServer里面看到的,在里面大量的使用这个运算符 ,当时还看的莫名其妙 ,好像"? : "这个三元运算符.
不过它完成的功能确实和"? : "相似 ,只是在特定条件下更简洁了.
输出的内容是这个:
a:test1 b: c:test1, d:test3
补充一下:
??左边的内容如果不为空则返回左值的内容,如果为空则返回右值的内容。
不过这个符号貌似不常用,或者基本没看到什么人用,毕竟不广泛