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 集合

posted @ 2021-08-09 12:08  匿鱼  阅读(46)  评论(0)    收藏  举报