Dictionary<string,Vector3> temp =new Dictionary<string,Vector3>();//
temp.Add ("0", new Vector3 (0, 0, 0));
temp.Add ("1", new Vector3 (0, 1, 0));//给字典添加数据
Debug.Log (temp.Keys.Count);//读取当前字典长度
Vector3 testGet;
temp.Add ("0", new Vector3 (0, 0, 0));
temp.Add ("1", new Vector3 (0, 1, 0));//给字典添加数据
Debug.Log (temp.Keys.Count);//读取当前字典长度
Vector3 testGet;
temp.TryGetValue ("0", out testGet);//从字典里读取数据
Vector3 testGet=temp["1"];//也可以这样获取数据
Debug.Log (testGet);
最后包含字典的包
using System.Collections.Generic;
本文介绍了一个简单的C#字典操作实例,包括如何创建、添加数据到字典、读取字典长度及从字典中获取数据的方法。
1万+





