单问号---为泛型 Nullable<int> 的简写方式.
双问号---用于判断前一个操作数是否为null,如为null则"返回"后一个操作数,否则"返回"前一个操作数.
publicint? para =null;
//public int para;如果不注释掉此行,而把上一行注释掉的话,下面会报错!
publicint par()
{
returnthis.para ??0;
}
执行下面程序,返回值为 8
publicint? para =8;
//public int para;如果不注释掉此行,而把上一行注释掉的话,下面会报错!
publicint par()
{
returnthis.para ??0;
}
执行下面程序,返回值为 12
class Program
{
publicint? paral =12;
staticvoid Main(string[] args)
{
Program program =new Program();
Console.WriteLine(program.Para());
}
publicint Para()
{
returnthis.paral ??8;
}
}
执行下面程序 返回值为 0
class Program
{
publicint? paral =0;
staticvoid Main(string[] args)
{
Program program =new Program();
Console.WriteLine(program.Para());
}
publicint Para()
{
returnthis.paral ??8;
}
}