dictionary vs Hashtables

2022-10-16

dictionary
dictionary is generic type dictionary<tkey,tvalue>
dictionary class is a strong type < tkey,tvalue > hence, you must specify the data types for key and value.
there is no need of boxing/unboxing.
when you try to access non existing key dictionary, it gives runtime error.
dictionary maintains an order of the stored values.
there is no need of boxing/unboxing, so it is faster than hashtable.
hashtable
hashtable is non-generic type.
hashtable is a weakly typed data structure, so you can add keys and values of any object type.
values need to have boxing/unboxing.
when you try to access non existing key hashtable, it gives null values.
hashtable never maintains an order of the stored values.
hashtable needs boxing/unboxing, so it is slower than dictionary.

《dictionary vs Hashtables.doc》

下载本文的Word格式文档,以方便收藏与打印。