C# Hashtable Use, Lookups and Examples
You want to use the Hashtable collection in the best way, for either an older program written in the C# language or for maintaining a program. The Hashtable provides a fast and simple interface, in many ways simpler than Dictionary. Here we see how you can use the Hashtable collection in the C# programming language, providing a fast lookup collection for hashing keys to values in a constant-time data structure.
Create Hashtable and add entries
First here we see how you can create a new Hashtable with the simplest, parameterless constructor. When it is created, the Hashtable has no values, but we can directly assign values with the indexer, which uses the square brackets [ ]. The example adds three integer keys with one string value each.
Add entries to Hashtable and display them [C#]
using System;
using System.Collections;
class Program
{
static void Main()
{
Hashtable hashtable = new Hashtable();
hashtable[1] = "One";