Get an IDictionaryEnumerator object that iterates through a SortedList in CSharp

Description

The following code shows how to get an IDictionaryEnumerator object that iterates through a SortedList.

Example


using System;//from w w  w. j a v a2 s  .c o  m
using System.Collections;

public class HashtableExample
{
    public static void Main()
    {
        SortedList myHT = new SortedList();
        myHT.Add("1", "4");
        myHT.Add("2", "5");
        myHT.Add("3", "6");

        IDictionaryEnumerator denum = myHT.GetEnumerator();
        DictionaryEntry dentry;

        while (denum.MoveNext())
        {
            dentry = (DictionaryEntry) denum.Current;
            Console.WriteLine("    {0,-17}{1}", dentry.Key, dentry.Value);
        }
    }
}

The code above generates the following result.





















Home »
  C# Tutorial »
    Collections »




ArrayList
BitArray
Collection
Comparer
HashSet
Hashtable
LinkedList
List
ListDictionary
OrderedDictionary
Queue
SortedList
SortedSet
Stack
StringCollection
StringDictionary