码迷,mamicode.com
首页 > 其他好文 > 详细

How to sort the dictionary by the value field

时间:2015-11-29 17:59:29      阅读:112      评论:0      收藏:0      [点我收藏+]

标签:

            // Sort dictionary by the value field
            List<KeyValuePair<int, int>> redBallsList = redBallsDict.ToList();
            List<KeyValuePair<int, int>> blueBallsList = blueBallsDict.ToList();

            redBallsList.Sort((firstPair, nextPair) =>
            {
                //return nextPair.Value.CompareTo(firstPair.Value);
                return -1 * firstPair.Value.CompareTo(nextPair.Value);
            }
            );

            blueBallsList.Sort((firstPair, nextPair) =>
            {
                //return nextPair.Value.CompareTo(firstPair.Value);
                return -1 * firstPair.Value.CompareTo(nextPair.Value);
            }
            );

            // Sort an int Arrary
            int[] PerfectBallsIntArr = new int[6];
            for (int i = 0; i < 6; i++)
            {
                PerfectBallsIntArr[i] = Convert.ToInt32(PerfectBallsArr[i]);
            }

            Array.Sort(PerfectBallsIntArr);

 

How to sort the dictionary by the value field

标签:

原文地址:http://www.cnblogs.com/researcher/p/5004985.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!