C#字典的遍歷方法

命名空間:  System.Collections.Generic

Dictionary<TKey, TValue> 類

KeyValuePair<TKey, TValue> 結構

用指定的鍵和值初始化 KeyValuePair<TKey, TValue> 結構的新實例。


        Dictionary<string, int> data = new Dictionary<string, int>();
        data.Add("a", 1);
        data.Add("b", 2);
        data.Add("c", 3);
        foreach (KeyValuePair<string , int> item in data)
        {
            Debug.Log(item.Key+" = "  + item.Value);
        }


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章