现在有一个ListDictionary对象,如何能把key和values都遍历出来?

解决方案 »

  1.   

    public static void Main()  {      // Creates and initializes a new ListDictionary.
          ListDictionary myCol = new ListDictionary();
          myCol.Add( "Braeburn Apples", "1.49" );
          myCol.Add( "Fuji Apples", "1.29" );
          myCol.Add( "Gala Apples", "1.49" );
          myCol.Add( "Golden Delicious Apples", "1.29" );
          myCol.Add( "Granny Smith Apples", "0.89" );
          myCol.Add( "Red Delicious Apples", "0.99" );      // Displays the values in the ListDictionary in three different ways.
          Console.WriteLine( "Initial contents of the ListDictionary:" );
          PrintKeysAndValues( myCol );      // Deletes a key.
          myCol.Remove( "Plums" );
          Console.WriteLine( "The collection contains the following elements after removing \"Plums\":" );
          PrintKeysAndValues( myCol );      // Clears the entire collection.
          myCol.Clear();
          Console.WriteLine( "The collection contains the following elements after it is cleared:" );
          PrintKeysAndValues( myCol );   }   public static void PrintKeysAndValues( IDictionary myCol )  {
          Console.WriteLine( "   KEY                       VALUE" );
          foreach ( DictionaryEntry de in myCol )
             Console.WriteLine( "   {0,-25} {1}", de.Key, de.Value );
          Console.WriteLine();
       }
      

  2.   

    http://msdn.microsoft.com/zh-cn/library/system.collections.specialized.listdictionary.add(VS.80).aspx有啥问题就去查查的
      

  3.   

    using System.Collections.Specialized;
    ListDictionary ld = new ListDictionary();
    ld.Keys.CopyTo(Array ary,0)
    ld.Values.CopyTo(Array ary,0)
      

  4.   

    foreach (DictionaryEntry de in myListDictionary))
    {
          de.Key
          de.Value
    }
      

  5.   

    ListDictionary   Dictionary<>
    ListDictionary myCol = new ListDictionary();
    foreach ( DictionaryEntry de in myCol )
             Console.WriteLine("{0} {1}", de.Key, de.Value );