Adds an entry with the specified key and value into the ListDictionary. : ListDictionary « Collections Data Structure « C# / C Sharp






Adds an entry with the specified key and value into the ListDictionary.

 

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" );

      PrintKeysAndValues( myCol );

      myCol.Remove( "A" );
      PrintKeysAndValues( myCol );
      myCol.Clear();
      PrintKeysAndValues( myCol );
   }
   public static void PrintKeysAndValues( IDictionary myCol )  {
      foreach ( DictionaryEntry de in myCol )
         Console.WriteLine( "   {0,-25} {1}", de.Key, de.Value );
   }

}

   
  








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.Display the contents of the collection using the enumerator
4.Displays the elements using the Keys, Values, Count, and Item properties
5.Copies the ListDictionary to an array with DictionaryEntry elements
6.Searches for a key
7.Deletes a key
8.Determines whether the ListDictionary contains a specific key.