cipher = new Dictionary<char,int>;
cipher.Add( 'a', 324 );
cipher.Add( 'b', 553 );
cipher.Add( 'c', 915 );
How to get the 2nd element? For example, I'd like something like:
KeyValuePair pair = cipher[1]
Where pair contains ( 'b', 553 )
Based on the coop's suggestion using a List, things are working:
List<KeyValuePair<char, int>> cipher = new List<KeyValuePair<char, int>>();
cipher.Add( new KeyValuePair<char, int>( 'a', 324 ) );
cipher.Add( new KeyValuePair<char, int>( 'b', 553 ) );
cipher.Add( new KeyValuePair<char, int>( 'c', 915 ) );
KeyValuePair<char, int> pair = cipher[ 1 ];
Assuming that I'm correct that the items stay in the list in the order they are added, I believe that I can just use a List
as opposed to a SortedList
as suggested.