成都网站建设设计

将想法与焦点和您一起共享

用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排序-创新互联
URL分享:http://chengdu.cdxwcx.cn/article/doppoc.html