Dictionary是存储键和值的集合
Dictionary是无序的,键Key是唯一的
Dictionary<Key,Value> dic = new Dictionary<Key,Value>();
Dictionary<string, int> dic = new Dictionary<string, int>();
//Add方法来添加键值对
dic.Add("YAOER",20);
dic.Add("FenLi", 18);
dic.Add("BaoBao", 20);
dic.Add("BaoBei", 18);
//获取当前字典中KeyValue的个数
int count = dic.Count;
Console.WriteLine("当前字典里有"+count+"个KeyValue");
//检查字典中是否包含指定的Key
bool b = dic.ContainsKey("YAOER");
//检查字典中是否包含指定的Key
bool c = dic.ContainsValue(20);
//尝试获取指定的Key所对应的Value
int s;
bool bb = dic.TryGetValue("YAOER", out s);
//如果当前字典中包含YAOER这个Key,那么就获取对应的Value并保存在s中,bb=true
//如果当前字典中不包含YAOER这个Key,那么 s = null,bb = false
//通过Key获取Value
int age = dic["YAOER"];
Console.WriteLine(age);
//Remove方法来移除键值对
dic.Remove("YAOER");
//清空当前字典
dic.Clear();