Logo

Programming-Idioms

History of Idiom 113 > diff from v27 to v28

Edit summary for version 28 by bigwavedave:
[Csharp] Forgot to add Imports

Version 27

2019-10-08, 20:58:25

Version 28

2019-10-08, 21:02:05

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
Imports
Imports
using System.Collections.Generic;
using System.Linq;
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);
}
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);
}