(轉)C#中兩個問號和一個問號 ??


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


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM