Question:Which of the following is the correct way to sort a C# dictionary by value? 

A List<KeyValuePair<string, string>> myList = aDictionary.ToList(); myList.Sort( delegate(KeyValuePair<string, string> firstPair, KeyValuePair<string, string> nextPair) { return firstPair.Value.CompareTo(nextPair.Value); } ); 

B List<KeyValuePair<string, string>> myList = aDictionary.ToList(); myList.Sort((firstPair,nextPair) => { return firstPair.Value.CompareTo(nextPair.Value); } ); 

C foreach (KeyValuePair<string,int> item in keywordCounts.OrderBy(key=> key.Value)) { // do something with item.Key and item.Value } 

D var ordered = dict.OrderBy(x => x.Value); 

+ Answer
+ Report
Total Preview: 1900

Copyright © 2024. Powered by Intellect Software Ltd