Get an enumerator that iterates through the string dictionary in CSharp

Description

The following code shows how to get an enumerator that iterates through the string dictionary.

Example


using System;/*from  w  ww .j  a  v  a2s . com*/
using System.Collections;
using System.Collections.Specialized;

public class SamplesStringDictionary  {

   public static void Main()  {
      StringDictionary myCol = new StringDictionary();
      myCol.Add( "red", "rojo" );
      myCol.Add( "green", "verde" );
      myCol.Add( "blue", "azul" );

      IEnumerator myEnumerator = myCol.GetEnumerator();
      DictionaryEntry de;
      while ( myEnumerator.MoveNext() )  {
         de = (DictionaryEntry) myEnumerator.Current;
         Console.WriteLine(de.Key + "" + de.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