在C#中对数组进行排序示例
namespace demo_array { class Program { static void Main(string[] args) { //使用Array.Sort排序字符串 string[] a = new string[] { "apple", "pear", "peach", "apple", "grape" }; Array.Sort(a); foreach (string s in a) { Console.WriteLine(s); } Console.ReadKey(); //使用 Array.Sort 排序数字示例 int[] b = new int[] { 2,5,4,1,8,9,7,5,6 }; Array.Sort(b); foreach (int s in b) { Console.WriteLine(s); } Console.ReadKey(); } } }
在本文中,我将解释如何在数组中排序数组。
我们可以调用静态Arraysort方法并使用它来对串数组进行排序。
结果是按照字母顺序进行排序。
日期:2020-04-11 23:03:51 来源:oir作者:oir