How is HashTable different from ArrayList in .NET?

The differences between HashTable and ArrayList are tabulated below: Today's Special Deals
Great Savings... Everyday!
Tuesday, January 19th, 2021

It is a map. It is a list.
You can add element to ArrayList using add method as shown below:
ArrayList sample = new ArrayList();
Here implicit key is the index position in which the element is stored which is always numeric.
You can add element to HashTable in the form of key-value pair using add method as shown below:
HashTable sample = new HashTable();
Key can be numeric or alpha.
Retrieving elements is faster since you retrieve an element using its key. Retrieval is comparatively slow since you iterate over the elements in the list to retrieve a specific element.
In an ArrayList, you can store elements of the same type only. If you store elements of different types in the same ArrayList then you will get run time error while retrieving it. You will retrieve and display elements of ArrayList as shown below:
foreach(<datatype> element in <ArrayList>) {
In the same HashTable, you can store elements of different data types and retrieve them without any errors using DictionaryEntry as shown below:
foreach(Dictionaryentry dirSample in <HashTable>.keys.values){
+ "," + dirSample.values);

FREE Subscription

Subscribe to our mailing list and receive new articles
through email. Keep yourself updated with latest
developments in the industry.


Note : We never rent, trade, or sell my email lists to
anyone. We assure that your privacy is respected
and protected.

Visit .NET Programming Tutorial Homepage


Recommended Resource

| How do you implement Observer Design Pattern in .NET? | How do you pass data between different Tiers in .NET Architecture? | How is Classic ADO different from ADO.NET? | How is Dataadapter useful in ADO.NET? | How is Datareader different from Dataset in ADO.NET? | How is .NET Application Development different from Traditional Development? | How is HashTable different from ArrayList in .NET? | How is Inheritance achieved in C#? | How is new keyword different from override keyword during inheritance in .NET? | How is String class different from StringBuilder class in .NET? | Illustrate ADO.NET Architecture | Illustrate the importance of Server.Transfer and Response.Redirect in .NET? | Mention the different objects available in Dataset of ADO.NET | Mention the usage of Connection Object in ADO.NET | What are the commonly used methods of Dataadapter in ADO.NET? | What are the different Behavioral Design Patterns that can be used in .NET Architecture? | What are the different Creational Design Patterns that can be used in .NET Architecture? | What are the different Structural Design Patterns that can be used in .NET Architecture? | What are the methods provided by Command Objects in ADO.NET? | What is Internal Access Modifier in C#? |

“Amazon and the Amazon logo are trademarks of, Inc. or its affiliates.”

| Privacy Policy for | Disclosure | Contact |

Copyright - © 2004 - 2021 - All Rights Reserved.