昨天有练习对数字阵列进行排序,《https://www.cnblogs.com/insus/p/10825174.html

其实一切都弄得很复杂,array已经有2个方法OrderBy和OrderByDescending:

参考下面代码演示:

关于数组的ORDERBY自带函数

 

关于数组的ORDERBY自带函数
 int[] ints = { 10, 45, 15, 39, 21, 26 };
           
            foreach (var i in ints.OrderBy(g => g))
            {
                System.Console.Write(i + " ");
            }


            Console.WriteLine();
            var str = new string('-', 10);
            Console.Write(str);
            Console.WriteLine();

            
            foreach (var i in ints.OrderByDescending(g => g))
            {
                System.Console.Write(i + " ");
            }
            Console.WriteLine();
关于数组的ORDERBY自带函数

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2021-11-18
  • 2021-08-14
  • 2021-04-13
  • 2021-09-24
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2021-12-25
  • 2022-12-23
  • 2022-12-23
  • 2021-04-10
  • 2021-07-26
  • 2021-09-28
相关资源
相似解决方案