现在的位置: 首页 > 综合 > 正文

C#中两个问号和一个问号

2012年01月15日 ⁄ 综合 ⁄ 共 405字 ⁄ 字号 评论关闭

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

抱歉!评论已关闭.