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));
    }

运行结果:

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM