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,取所赋值??右边的。

相关文章:

  • 2021-12-16
  • 2021-07-17
  • 2022-12-23
  • 2022-12-23
  • 2021-09-07
  • 2021-05-25
  • 2021-08-21
猜你喜欢
  • 2021-09-19
  • 2021-08-28
  • 2022-02-06
  • 2022-01-20
相关资源
相似解决方案