标签:c# sort
目前集合用得最多的是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# Sort默认为升序 a-b , 若要将其将为降序 则是-(a-b) 也就是 b-a
本文出自 “Better_Power_Wisdom” 博客,请务必保留此出处http://aonaufly.blog.51cto.com/3554853/1851884
标签:c# sort
原文地址:http://aonaufly.blog.51cto.com/3554853/1851884