Dictionary<string, int> list = new Dictionary<string, int>();
list.Add("1", 1);
//
foreach(var item in list)
{
Debug.Log(item.Key + item.Value);
}
//使用KeyValuePair
foreach(KeyValuePair<string,int> item in list)
{
Debug.Log(item.Key + item.Value);
}
//通过键的集合取值
foreach(string key in list.Keys)
{
Debug.Log(key+list[key]);
}
//直接取址
foreach(int val in list.Values)
{
Debug.Log(val);
}
//for
List<string> test = new List<string>(list.Keys);
for(int i = 0; i < list.Count;i++)
{
Debug.Log(test[i] + list[test[i]]);
}
字典遍历方法
最新推荐文章于 2024-08-07 14:00:23 发布