Mega Code Archive

 
Categories / C# / Collections Data Structure
 

Copies the ListDictionary to an array with DictionaryEntry elements

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" );       // Copies the ListDictionary to an array with DictionaryEntry elements.       DictionaryEntry[] myArr = new DictionaryEntry[myCol.Count];       myCol.CopyTo( myArr, 0 );       // Displays the values in the array.       Console.WriteLine( "Displays the elements in the array:" );       Console.WriteLine( "   KEY                       VALUE" );       for ( int i = 0; i < myArr.Length; i++ )          Console.WriteLine( "   {0,-25} {1}", myArr[i].Key, myArr[i].Value );    }    }