Logo

Programming-Idioms

History of Idiom 113 > diff from v26 to v27

Edit summary for version 27 by bigwavedave:
New Csharp implementation by user [bigwavedave]

Version 26

2019-09-27, 21:55:27

Version 27

2019-10-08, 20:58:25

Idiom #113 Iterate over map entries, ordered by values

Print each key k with its value x from an associative array mymap, in ascending order of x.
Note that multiple entries may exist for the same value x.

Idiom #113 Iterate over map entries, ordered by values

Print each key k with its value x from an associative array mymap, in ascending order of x.
Note that multiple entries may exist for the same value x.

Extra Keywords
traverse traversal
Extra Keywords
traverse traversal
Code
Dictionary<String, String> mymap = new Dictionary<String, String>();
  
foreach(KeyValuePair<string, string> a in mymap.OrderBy(x => x.Value))
{
  Console.WriteLine("Key = {0}, Value = {1}", a.Key, a.Value);
}