首页 > 代码库 > C# 排序
C# 排序
目前集合用得最多的是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# 排序
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。