前言
简述,关于C#字典用法,T 代表类型
声明 - 实例
//声明空间未实例
Dictionary<TKey, TValue> dictionary;
//实例类型为<T, T>的字典
//<TKey, TValue> → <Key, value>键值对 Key具有唯一性 Value可相同
dictionary = new Dictionary<TKey, TValue>();
字典长度
//count = 0 索引位不可用
int count = dictionary.Count;
增
//顺次向后增加Key-Value键值对
//若Keys为断续序列 则优先添加到前面的索引位键值对为空的位置
dictionary.Add(tKey, tValue);
删
//删除目标Key关联的键值对
//对应索引位上的键值对置空 不影响其他键值对索引位
dictionary.Remove(tKey);
改
//按Key值索引对应Value值 直接赋值
dictionary[tKey]