C#_基本数据结构(字典|列表|链表|HashTable)
A 字典
1 void Start() { 2 enemyDic.Add("A",transform);//增 3 enemyDic.Add("B",transform);//增 4 5 if (enemyDic.ContainsKey("A")) {//查 6 enemyDic.Remove("A");//删 7 } 8 9 if (enemyDic.ContainsKey("B")) {//查 10 enemyDic["B"] = null;//改 - Value (Key 不可修改,可以删除后重新 Add) 11 } 12 }
B 列表
1 private void Start() { 2 List<string> temp = new List<string>(); 3 temp.Add("AA");//增 4 for (int i = 0; i < temp.Count; i++) { 5 if (temp[i] == "AA") { 6 temp[i] = "CC";//改 7 } 8 } 9 10 temp.Contains("AA");//查 => false 11 temp.Remove("CC");//删 12 }
C 链表
D HashTable
1 Hashtable ht = new Hashtable(); 2 ht.Add ("pid", 123); 3 ht.Add ("tid", 333); 4 ht.Add ("name", "wh"); 5 6 ICollection key = ht.Keys; 7 string log = ""; 8 foreach (string k in key) { 9 log += k + ": " + ht[k] + "|"; 10 } 11 Debug.LogError(log);
E Collection 集合