Posts

Difference between Hashtable and Dictionary in C#

In C#, Dictionary is a generic collection which is generally used to store key/value pairs. Dictionary is defined under  System.Collection.Generics namespace. It is dynamic in nature means the size of the dictionary is growing according to the need. A Hashtable is a collection of key/value pairs that are arranged based on the hash code of the key. Or in other words, a Hashtable is used to create a collection which uses a hash table for storage. It is the non-generic type of collection which is defined in  System.Collections namespace. In Hashtable, key objects must be immutable as long as they are used as keys in the Hashtable. Example: // C# program to illustrate a hashtable using System; using System.Collections;     class GFG {          // Main method      static public void Main()      {              // Create a hashtable          // Using Hashtable class          Hashtable my_hashtable = new Hashtable();