Hello unity3d!

C#中List的方法RemoveAt小测试

结论:在C#中将一个List中的项插入到别一个List中,会复制,而不是从源List中移除。

示例如下

    void Start () {
        TestList ();
    }

    void TestList () {
        Debug.Log ("list方法测试");

        List<string> list1 = new List<string> (){"aa", "bb", "cc"};
        List<string> list2 = new List<string> (){"dd", "ee", "ff"};

        Debug.Log ("before:" + list1.Count + ", " + list2.Count); 
        list2.Insert (0, list1 [0]);
        list1.RemoveAt (0);

        Debug.Log ("after:" + list1.Count + ", " + list2.Count);
        Debug.Log("list1:" + Utils.PrintList (list1));
        Debug.Log("list2:" + Utils.PrintList (list2));
    }

运行结果:

 

posted @ 2016-10-12 19:47  子非鱼`  阅读(7064)  评论(0编辑  收藏  举报
;