目前集合用得最多的是Array和List,现对这2个Array和List的排序,做一些测试:

先上栗子:

            Int32[] _testSort = new Int32[] { 1, 4, 2, 6, 8, 18, 3, 5, 9, 7, 11, 10 };
            Array.Sort(_testSort, (a, b) => b-a);
            for (int i = 0; i < _testSort.Length; i += 1)
            {
                Console.WriteLine(_testSort[i]);
            }


            Console.WriteLine("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");

            List<Int32> _listSort = new List<int>() { 1, 4, 2, 6, 8, 18, 3, 5, 9, 7, 11, 10 };
            _listSort.Sort((a, b) => b - a);
            for (int i = 0; i < _listSort.Count; i += 1 )
            {
                Console.WriteLine(_listSort[i]);
            }
                Console.ReadLine();


打印结果 :

C# 排序_C

C# Sort默认为升序 a-b , 若要将其将为降序 则是-(a-b) 也就是 b-a