Display the contents of the collection using the enumerator : ListDictionary « Collections Data Structure « C# / C Sharp






Display the contents of the collection using the enumerator

 

using System;
using System.Collections;
using System.Collections.Specialized;

public class SamplesListDictionary  {

   public static void Main()  {
      ListDictionary myCol = new ListDictionary();
      myCol.Add( "A", "1.49" );
      myCol.Add( "B", "1.29" );
      myCol.Add( "C", "0.99" );


      Console.WriteLine( "Displays the elements using the IDictionaryEnumerator:" );
      PrintKeysAndValues2( myCol );

   }
   public static void PrintKeysAndValues2( IDictionary myCol )  {
      IDictionaryEnumerator myEnumerator = myCol.GetEnumerator();
      Console.WriteLine( "   KEY                       VALUE" );
      while ( myEnumerator.MoveNext() )
         Console.WriteLine( "   {0,-25} {1}", myEnumerator.Key, myEnumerator.Value );
      Console.WriteLine();
   }
   
}

   
  








Related examples in the same category

1.ListDictionary Class implements IDictionary using a singly linked list
2.Display the contents of the collection using foreach. This is the preferred method
3.Displays the elements using the Keys, Values, Count, and Item properties
4.Copies the ListDictionary to an array with DictionaryEntry elements
5.Searches for a key
6.Deletes a key
7.Adds an entry with the specified key and value into the ListDictionary.
8.Determines whether the ListDictionary contains a specific key.