Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/330.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
将C#键值对列表排序到另一个键值对列表中_C#_List_Sorting_C# 4.0 - Fatal编程技术网

将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))