C#中兩個問號的雙目運算符
view sourceprint?
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
int? a;
a = null;//此時輸出3
//a = 6;//此時輸出6
int b = a ?? 3;
Console.Write(b);
Console.ReadKey();
}
}
}
變量定義中含有一個問號,意思是這個數據類型是NullAble類型的。
變量定義中含有兩個問號,意思是取所賦值??左邊的,如果左邊為null,取所賦值??右邊的。