Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/34.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# 使用linq命令keyvaluepair_C#_Asp.net_Linq - Fatal编程技术网

C# 使用linq命令keyvaluepair

C# 使用linq命令keyvaluepair,c#,asp.net,linq,C#,Asp.net,Linq,我有以下清单keyvaluepair var countryList = new List<KeyValuePair<string,int>>(); 您可以猜到它不起作用,我知道为什么是s[0],但有人能告诉我正确的语法是什么吗 谢谢我想换成一行 var sortedCountryList = countryList.OrderBy(s=>s.Key); 如果你只想把国家的名字列在名单上 var sortedCountryList = countryLis

我有以下清单keyvaluepair

   var countryList = new List<KeyValuePair<string,int>>();
您可以猜到它不起作用,我知道为什么是s[0],但有人能告诉我正确的语法是什么吗


谢谢

我想换成一行

var sortedCountryList = countryList.OrderBy(s=>s.Key);
如果你只想把国家的名字列在名单上

var sortedCountryList = countryList.OrderBy(s=>s.Key).Select(s=>s.Value);

你为什么不先订购数据库呢?
var lst = from s in countryList
      orderby s.Key
      select s;
var sortedCountryList = countryList.OrderBy(s=>s.Key);
var sortedCountryList = countryList.OrderBy(s=>s.Key).Select(s=>s.Value);