您的位置:首页 > 其它

.net3.5下利用Linq新特性对Dictionary进行快速排序

2009-08-01 17:10 483 查看
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();
}
}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐