C# Hashtable Hashtable()
Description
Hashtable Hashtable()
initializes a new, empty instance
of the Hashtable class using the default initial capacity, load factor,
hash code provider, and comparer.
Syntax
Hashtable.Hashtable()
has the following syntax.
public Hashtable()
Example
The following code uses foreach statement to loop through all keys in a hashtable.
using System;//www . j ava 2s .co m
using System.Collections;
class MainClass
{
public static void Main()
{
Hashtable hash = new Hashtable();
hash.Add("A", "1");
hash.Add("B", "2");
hash.Add("C", "3");
hash.Add("D", "4");
hash.Add("E", "5");
foreach (string firstName in hash.Keys)
{
Console.WriteLine("{0} {1}", firstName, hash[firstName]);
}
}
}
The code above generates the following result.