using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace Dic排序 { class Program { static void Main(string[] args) { Dictionary<string, int> dic = new Dictionary<string, int>(); dic.Add("q", 3); dic.Add("d", 9); dic.Add("f", 5); dic.Add("g", 6); dic.Add("l", 1); dic.Add("h", 0); //ascending升序 //descending降序 var dicSort = from objDic in dic orderby objDic.Value ascending select objDic; //int num = dicSort.Count();集合的个数 //int a = dicSort.ElementAt(0).Value;指定索引0的值 //也可以用for循环 foreach (KeyValuePair<string, int> kvp in dicSort) { Console.WriteLine(kvp.Key + ":" + kvp.Value); } Console.ReadKey(); } }