Copy ListDictionary to Array instance at the specified index in CSharp

Description

The following code shows how to copy ListDictionary to Array instance at the specified index.

Example


//  ww w.  j  a  va2 s  .com
using System;
using System.Collections;
using System.Collections.Specialized;

public class SamplesListDictionary  {
   public static void Main()  {
      ListDictionary myCol = new ListDictionary();
      myCol.Add( "F", "1.49" );
      myCol.Add( "A", "1.29" );
      myCol.Add( "B", "1.49" );
      myCol.Add( "C", "1.29" );
      myCol.Add( "D", "0.89" );
      myCol.Add( "E", "0.99" );

      DictionaryEntry[] myArr = new DictionaryEntry[myCol.Count];
      myCol.CopyTo( myArr, 0 );
      
      for(int i=0;i<myArr.Length;i++){
         Console.WriteLine(myArr[i].Key+ "" + myArr[i].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