Hashtable
- เข้าถึง Element ด้วย Key มี Key/Value Pair
- Thread-safe (Members)
- Return Null ถ้า Key ไม่มี
- Non-generic Type
- ช้ากว่า Dictionary (ต้อง Boxing/Unboxing)
- ประกาศ:
Hashtable ht = new Hashtable();
Dictionary
- Generic Type:
Dictionary<TKey, TValue>ในSystem.Collections.Generic - Throw Error ถ้า Key ไม่มี (KeyNotFoundException)
- เร็วกว่า Hashtable (ไม่ Boxing/Unboxing)
- ประกาศ:
IDictionary<int, string> d = new Dictionary<int, string>();
สรุป: ควรใช้ Dictionary สำหรับ Type Safety และ Performance