C#语法补充(一)

  1. 索引器
    string[] sk = { "niah", "ai", "renw" };

    public string this[int index]
    {
        get
        {
            return sk[index];
        }
        set
        {
            sk[index] = value;
        }
    }

    // Use this for initialization
    void Start()
    {
        this[2] = "ni";
        print(sk[2]);
    }

  1. 可空类型
        int? sk = null;
        int num = sk ?? 5;
        ListNode bill = null;
        ListNode ob = bill ?? new ListNode(3);
        print(num);
        print(ob.val);

猜你喜欢

转载自blog.csdn.net/qq_37811712/article/details/86027006