文章目录
一.添加
- 一.添加
- 二.获取
- 方式1:【Try Get Value】
- 方式2:【字典名[ 键的名字] 】
- 方式3:【使用索引获取】
Dictionary dic = new Dictionary();
dic.Add(5, "5555");
dic.Add(6, "6666");
dic.Add(7, "7777");
dic.Add(8, "8888");
dic.Add(9, "9999");
二.获取
方式1:【Try Get Value】
例如:
string value = null;
dic.TryGetValue(5, out value);
Debug.Log(value); //打印结果是 5555
方式2:【字典名[ 键的名字] 】
例如
Debug.Log(dic[5]); //打印结果是 5555
方式3:【使用索引获取】
导入:using System.Linq; 命名空间
dic.ElementAt(4).Value; //▶打印结果是: 99999
dic.ElementAt(4); //打印结果是: [9, 99999]