Mega Code Archive

 
Categories / C# / Collections Data Structure
 

Displays the elements using the Keys, Values, Count, and Item properties

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" );       PrintKeysAndValues3( myCol );    }    public static void PrintKeysAndValues3( ListDictionary myCol )  {       String[] myKeys = new String[myCol.Count];       myCol.Keys.CopyTo( myKeys, 0 );       Console.WriteLine( "   INDEX KEY                       VALUE" );       for ( int i = 0; i < myCol.Count; i++ )          Console.WriteLine( "   {0,-5} {1,-25} {2}", i, myKeys[i], myCol[myKeys[i]] );       Console.WriteLine();    }     }