Example

using System;
using System.Collections;

namespace Samples
{
  public class IDictionarySample
  {
    public static void Main()
    {
      IDictionary id = new Hashtable();
      id.Add(1, "damien");
      id.Add(2, "mark");
      id.Add(3, "brad");
      DisplayDictionary(id);
      SortedList sl = new SortedList();
      sl.Add(1, "maire");
      sl.Add(2, "sacha");
      sl.Add(3, "tamara");
      DisplayDictionary(sl);
    }
    public static void DisplayDictionary(IDictionary id)
    {
      Console.WriteLine("Is fixed size: {0}", id.IsFixedSize);
      Console.WriteLine("Is read only: {0}", id.IsReadOnly);
      Console.WriteLine("Count: {0}", id.Count );
      Console.WriteLine("Number of keys: {0}", id.Keys.Count);
      foreach(DictionaryEntry de in id)
        Console.WriteLine("Key: {0} Value: {1}",
                          de.Key,
                          de.Value);
    }
  }
}
The output is
 Is fixed ...

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.