Example

using System;
using System.Collections;

namespace Samples
{
  public class HashtableSample
  {
    public static void Main()
    {
      Hashtable ht = new Hashtable();
      ht.Add(1, "damien");
      ht.Add(4, "maire");
      ht.Add(2, "mark");
      ht.Add(5, "sacha");
      ht.Add(3, "brad");
      ht.Add(6, "tamara");
      DisplayHashtable(ht);
    }
    public static void DisplayHashtable(Hashtable ht)
    {
      Console.WriteLine("Count: {0}", ht.Count );
      IDictionaryEnumerator de = ht.GetEnumerator();
      while(de.MoveNext())
        Console.WriteLine("Key: {0} :    Value: {1}",
                          de.Key,
                          de.Value);
    }
  }
}
The output is
Count: 6
Key: 6 :    Value: tamara
Key: 5 :    Value: sacha
Key: 4 :    Value: maire
Key: 3 :    Value: brad
Key: 2 :    Value: mark
Key: 1 :    Value: damien

Get .NET Framework Standard Library Annotated Reference, Volume 1: Base Class Library and Extended Numerics Library now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.