当我们的应用中学要使用键值对得结构时,我们就可以使用Dictionary<TKey, TValue>来保存我们的数据,下面是我认为比较常用的函数,
1.Add 把我们需要的数据加到字典中。
2.Clear 清空字典中的数据。
3.ContainsKey 确定字典中是否包含指定的键。
4.ContainsValue 确定字典中是否包含指定的值。
5.Remove 移除指定的键。
当我们需要遍历一个字典的时候也有相应的foreach循环,他的用法是这样的
Dictionary<int,int> dicInt=new Dictionary<int,int>();
foreach(KeyValuePair<int,int> kvp in dicInt)
{
Console.WriteLine("Key = {0}, Value = {1}", kvp.Key, kvp.Value);
}