In arraylist or array if we have to access any data we need to use the internal index id generated by the array list collection. For instance the below code snippet shows how the internal id is used to fetch data from array list.
In actual scenarios we hardly remember internal id’s generated by collection we would like to fetch the data by using some application defined key. There’s where hash table comes in to picture.
Hash table helps to locate data using keys as shown below. When we add data to hash table it also has a provision where we can add key with the data. This key will help us to fetch data later using key rather than using internal index id’s generated by collections.
This key is converted in to numeric hash value which is mapped with the key for quick lookup.
Difference between dictionary and Hashtable: -
Dictionary collection is a generic collection equivalent for hashtable. Hashtable allows you to add key and value of any type (i.e. objects). This leads to two problems one is boxing and unboxing issues and second it’s not strongly typed.
Also see the other following .NET Generic interview questions video on boxing and unboxing: -