日期:2014-05-17 浏览次数:21072 次
int pos=1;//定义位置
Dictionary<int, string> sortedlist = new Dictionary<int, string>() {
{1,"one"},
{2,"two"},
{3,"three"}
};
Dictionary<int, string> sortedlist1 = sortedlist.Take(pos).ToDictionary(c=>c.Key,c=>c.Value);
sortedlist1.Add(2,"two.one");
Dictionary<int, string> sortedlist2 = sortedlist.Skip(pos).ToDictionary(c => c.Key+1, c => c.Value);
Dictionary<int, string> resultlist = sortedlist1.Concat(sortedlist2).ToDictionary(c => c.Key, c => c.Value);
/*
* + [0] {[1, one]} System.Collections.Generic.KeyValuePair<int,string>
+ [1] {[2, two.one]} System.Collections.Generic.KeyValuePair<int,string>
+ [2] {[3, two]} System.Collections.Generic.KeyValuePair<int,string>
+ [3] {[4, three]} System.Collections.Generic.KeyValuePair<int,string>
*/