2019년 3월 13일 수요일

Difference between Dictionary and Hashtable

Dictionary
  1. Dictionary is generic type Dictionary<TKey,TValue>
  2. Dictionary class is a strong type < TKey,TValue > Hence, you must specify the data types for key and value.
  3. There is no need of boxing/unboxing.
  4. When you try to access non existing key dictionary, it gives runtime error.
  5. Dictionary maintains an order of the stored values.
  6. There is no need of boxing/unboxing, so it is faster than Hashtable.
Hashtable
  1. Hashtable is non-generic type.
  2. Hashtable is a weakly typed data structure, so you can add keys and values of any object type.
  3. Values need to have boxing/unboxing.
  4. When you try to access non existing key Hashtable, it gives null values.
  5. Hashtable never maintains an order of the stored values.
  6. Hashtable needs boxing/unboxing, so it is slower than Dictionary.

댓글 없음:

댓글 쓰기