What is the difference between Hash Table and Arrays?

ASP.NET, C#



Views: 3546 | Community Opinion: 5

Tags..  .Net Interview  C# Interview

Bookmark this page..



Ask a New Question Go to Home

Community Opinion/Answers
 

Array vs HashTable

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.




Mohsin Mukri Said..

Array List
Size of array increase or Decrease Dynamically such type of array is called ArrayList.we can access value of array list using Index Value.

Hash Table
Same as Array list but we can remember index value this problem can overcom by hash table which allows us to define user Identified KEY Value using we can access any value from Hash Table.




rajan Said..

great




sandy Said..

both are same.................haha




vivek k Said..

Array and Hash table both are the collaction object but the main difference only is that
1.Array is a collection of same datatype
while
2.Hash table is a colletion of different datatype.






Register or Login to Post Your Opinion