成都创新互联网站制作重庆分公司

用LINQ对Dictionary排序-创新互联

代码如下 :用LINQ对Dictionary
排序
   static void Main(string[] args)
        {
            Dictionary di = new Dictionary();
            di.Add(9, 1);
            di.Add(0, 6);
            di.Add(2, 8);

var sortedDict = (from entry in di orderby entry.Key ascending select entry)
                .ToDictionary(pair=> pair.Key, pair => pair.Value);

foreach (var pair in di)
            {
                Console.WriteLine("{0},{1}", pair.Key, pair.Value);
            }

            Console.WriteLine("--------------------");

foreach (var pair in sortedDict)
            {
                Console.WriteLine("{0},{1}", pair.Key, pair.Value);
            }

            Console.ReadLine();
        }

方法来自stackoverflow

惠安ssl适用于网站、小程序/APP、API接口等需要进行数据传输应用场景,ssl证书未来市场广阔!成为创新互联公司的ssl证书销售渠道,可以享受市场价格4-6折优惠!如果有意向欢迎电话联系或者加微信:028-86922220(备注:SSL证书合作)期待与您的合作!

http://stackoverflow.com/questions/289/how-do-you-sort-a-c-sharp-dictionary-by-value


分享文章:用LINQ对Dictionary排序-创新互联
地址分享:http://cxhlcq.com/article/doppoc.html

其他资讯

在线咨询

微信咨询

电话咨询

028-86922220(工作日)

18980820575(7×24)

提交需求

返回顶部