淘先锋技术网

首页 1 2 3 4 5 6 7

using System;
using System.Collections.Generic;
using System.Text;
using System.Linq;

namespace DictionarySorting
{
    class Program
    {
        static void Main(string[] args)
        {
            Dictionary<int, int> dic = new Dictionary<int, int>();
            dic.Add(1, 158);
            dic.Add(5, 25);
            dic.Add(3, 215);
            dic.Add(2, 369);
            dic.Add(4, 147);

            var result = from pair in dic orderby pair.Value select pair;

            foreach (KeyValuePair<int, int> pair in result)
            {
                Console.WriteLine("Key:{0}, Value:{1}", pair.Key, pair.Value);
            }

            Console.ReadKey();
        }
    }
}