How to sort the dictionary by the value field

            // 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);

 

posted @ 2015-11-29 16:56  Researcher  阅读(136)  评论(0编辑  收藏  举报