using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace lianxi1
{
class Program
{
static void Main(string[] args)
{
Dictionary<int, int> d = new Dictionary<int, int>();
d[1] = 1;
d[2] = 2;
var keyvalues = from keyvalue in d orderby keyvalue.Value ascending select keyvalue;
foreach (var keyvalue in keyvalues)
if (!d.ContainsKey(3))
d[3] = 3;
foreach (var keyvalue in keyvalues)
Console.WriteLine(keyvalue.Value);
Console.ReadKey();
}
}
}
其他遍历方法参考https://www.cnblogs.com/wangchao928/archive/2012/05/17/2505671.html