結論:在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)); }
運行結果: