将C#键值对列表排序到另一个键值对列表中
这是我的名单将C#键值对列表排序到另一个键值对列表中,c#,list,sorting,c#-4.0,C#,List,Sorting,C# 4.0,这是我的名单 List<KeyValuePair<string, int>> lstRodsMonsterPool = new List<KeyValuePair<string, int>>(); List lstRodsMonsterPool=new List(); 现在我试着像这样对它进行排序,但它给出了一个错误 lstRodsMonsterPool = (from entry in lstRodsMonsterPool
List<KeyValuePair<string, int>> lstRodsMonsterPool = new List<KeyValuePair<string, int>>();
List lstRodsMonsterPool=new List();
现在我试着像这样对它进行排序,但它给出了一个错误
lstRodsMonsterPool = (from entry in lstRodsMonsterPool
orderby entry.Value ascending
select entry)
.ToList<new KeyValuePair<string,int>(pair => pair.Key, pair => pair.Value)>;
lstRodsMonsterPool=(来自lstRodsMonsterPool中的条目
orderby条目。值升序
选择条目)
.ToList pair.Key,pair=>pair.Value)>;
C#4.0
谢谢。
。ToList()
不接受参数。看起来您正在尝试对列表进行适当排序,因此可以使用:
lstRodsMonsterPool = lstRodsMonsterPool.OrderBy(x => x.Value).ToList();
“但这是给人的错误”-悬念…一旦你能看到整条线就很明显了,但OK+1!)thnx工作正常。知道和不喜欢“米奇小麦”的人很明显:)
lstRodsMonsterPool.Sort((l,r) => l.Value.CompareTo(r.Value))