Friday, May 30, 2008

Sắp xếp dữ liệu trong Dictionary bằng các Values

Dictionary<string, int> dict = new Dictionary<string, int>();
 
/* populate dictionary */
List<KeyValuePair<string, int>> summaryList = new List<KeyValuePair<string, int>>();
 
summaryList.AddRange(dict);
summaryList.Sort(
    delegate(KeyValuePair<string, int> kvp1, KeyValuePair<string, int> kvp2)
    {
        return Comparer<int>.Default.Compare(kvp1.Value, kvp2.Value);
    }
);

No comments:

Post a Comment