dictionary vs Hashtables


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.

posted @ 2019-09-08 18:01  FredGrit  阅读(311)  评论(0编辑  收藏  举报