What is the difference between HashTable and Arrays?

An array is a collection of data, where each data item (element) has to be the the same data type. Array elements are allocated consecutively in the same memory space and are indexed via an integer index.
Hash table is a data structure that provides lookup semantics via an object key. Typically the key is a string, however under .NET, it can be any Object and particualy objects that provide a decent override of the Base Objects GetHashCode() function. A hash code is an algorithically generated id that should make an object key distinct.
For instance under .NET, arrays are objects that derive from the base Array class and implement IEnumerable so that array elements can be enumerated with a For-Each loop.
Hash tables hold a collection of DictionaryEntry objects, where a DictionaryEntry holds the Key along with its value.
In another words hash table is derived from the CollectionBase class. Array is the base class of system.object.array is reference type. which is identified with the position of array for both insertion and retreival. But the HashTable is stored the data with unique key which helps to refer the data.

Tagged , . Bookmark the permalink.

Leave a Reply