//Sorts sections according to the key value stored on "sections" unsorted dictionary, which is passed as a constructor argumentSystem.Collections.Generic.SortedDictionary<int, string> sortedSections = null;if (sections != null){sortedSections = new SortedDictionary<int, string>(sections);}
Dim MyDictionary As SortedDictionary(Of String, MyDictionaryEntry)
MyDictionaryListView.ItemsSource = MyDictionary.Values.OrderByDescending(Function(entry) entry.MyValue)
Public Class MyDictionaryEntry ' Need Property for GridViewColumn DisplayMemberBindingPublic Property MyString As StringPublic Property MyValue As IntegerEnd Class
var dict = new SortedDictionary<string, int>();// ToDo: populate dict
var output = dict.OrderBy(e => e.Value).Select(e => new {frequency = e.Value, word = e.Key}).ToList();
foreach (var entry in output){Console.WriteLine("frequency:{0}, word: {1}",entry.frequency,entry.word);}
var items = new Dictionary<string, int>();items.Add("cat", 0);items.Add("dog", 20);items.Add("bear", 100);items.Add("lion", 50);
// Call OrderBy() method here on each item and provide them the IDs.foreach (var item in items.OrderBy(k => k.Key)){Console.WriteLine(item);// items are in sorted order}
你可以做一个把戏:
var sortedDictByOrder = items.OrderBy(v => v.Value);
或:
var sortedKeys = from pair in dictNameorderby pair.Value ascendingselect pair;