转载地址:http://blog.sina.com.cn/s/blog_5c5bc9070100pped.html
C#集合Dictionary中按值的降序排列 static void Main(string[] args)
{
Dictionary<string, int> dt = new Dictionary<string, int>();
dt.Add("美丽",);
dt.Add("校园",);
dt.Add("大学",); var result1 = from pair in dt select pair;
foreach (KeyValuePair<string, int> pair in result1)
{
Console.WriteLine(pair.Key.ToString() + " " + pair.Value.ToString());
}
Console.WriteLine(); var result2 = from pair in dt orderby pair.Value select pair;
foreach (KeyValuePair<string, int> pair in result2)
{
Console.WriteLine(pair.Key.ToString()+" "+pair.Value.ToString());
}
Console.WriteLine(); var result3 = from pair in dt orderby pair.Value descending select pair;
foreach (KeyValuePair<string, int> pair in result3)
{
Console.WriteLine(pair.Key.ToString() + " " + pair.Value.ToString());
}
Console.Read();
}