1、 C# 键值对类有如下类:web
一、IDictionary<string, Object> idc = new Dictionary<string, object>();安全
二、KeyValuePair<string, object> par = (KeyValuePair<string, object>)shoplistcomboBox.SelectedItem;多线程
三、Hashtable ht=new Hashtable(); file建立一个Hashtable实例
ht.Add(E,e);添加keyvalue键值对post
Hashtable 内的每一组对象就是一个DictionaryEntry
例如咱们要循环hashtable
foreach (DictionaryEntry de in myHashtable) {...}
Hashtable就是一个DictionaryEntry的集合spa
2、 KeyValuePair和Hashtable区别线程
一、KeyValuePair是单个的键值对对象,而Hashtable是一个集合。orm
二、KeyValuePair用于接收combox选定的值。对象
例如:KeyValuePair<string, object> par = (KeyValuePair<string, object>)shoplistcomboBox.SelectedItem;blog
3、 hashtable 与 dictionary的区别ci
一、单线程程序中推荐使用 Dictionary, 有泛型优点, 且读取速度较快, 容量利用更充分.
二、多线程程序中推荐使用 Hashtable, 默认的 Hashtable 容许单线程写入, 多线程读取, 对 Hashtable 进一步调用 Synchronized() 方法能够得到彻底线程安全的类型. 而 Dictionary 非线程安全, 必须人为使用 lock 语句进行保护, 效率大减.
三、Dictionary 有按插入顺序排列数据的特性 (注: 但当调用 Remove() 删除过节点后顺序被打乱), 所以在须要体现顺序的情境中使用 Dictionary 能得到必定方便.