C#中List的方法RemoveAt小测试

时间:2023-03-09 15:44:15
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 (, list1 []);
list1.RemoveAt (); Debug.Log ("after:" + list1.Count + ", " + list2.Count);
Debug.Log("list1:" + Utils.PrintList (list1));
Debug.Log("list2:" + Utils.PrintList (list2));
}

运行结果:

C#中List的方法RemoveAt小测试