- The Hashtable class and the Dictionary generic class implement the IDictionary interface. The Dictionary generic class also implements the IDictionary generic interface. Therefore, each element in these collections is a key-and-value pair.
- A Hashtable object consists of buckets that contain the elements of the collection. A bucket is a virtual subgroup of elements within the Hashtable, which makes searching and retrieving easier and faster than in most collections. Each bucket is associated with a hash code, generated using a hash function and based on the key of the element.
- When an object is added to a Hashtable, it is stored in the bucket that is associated with the hash code that matches the object�s hash code. When a value is being searched for in the Hashtable, the hash code is generated for that value, and the bucket associated with that hash code is searched.
- The Dictionary class has the same functionality as the Hashtable class. A Dictionary of a specific type (other than Object) has better performance than a Hashtable for value types because the elements of Hashtable are of type Object and, therefore, boxing and unboxing typically occur if storing or retrieving a value type.
Monday, 20 December 2010
Difference between Hashtable vs Dictionary?
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment