// Collection of code snippets by Arne Vajhøj // (likely posted to comp.os.vms/INFO-VAX, INFO-TPU, MACRO32, eksperten.dk, newz.dk, LinkedIn or other place sometime between 1990 and now) using System; using System.Linq; using System.Collections.Generic; namespace E { public class Program { public static void Main(string[] args) { Dictionary ht = new Dictionary(); ht["Carsten"] = "Jensen"; ht["Rasmus"] = "Andersen"; ht["Bo"] = "Bentzen"; var q1 = from k in ht.Keys orderby k select new KeyValuePair(k, ht[k]); foreach(KeyValuePair kvp in q1) { Console.WriteLine(kvp.Key + " -> " + kvp.Value); } var q2 = from k in ht.Keys orderby ht[k] select new KeyValuePair(k, ht[k]); foreach(KeyValuePair kvp in q2) { Console.WriteLine(kvp.Key + " -> " + kvp.Value); } } } }