//方法类 using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace Cp4 { class SelectSorter { //按由小到大的顺序,对数组进行排序 public static void SelectSortAscending(int[] arr) { for (int i = 0; i < arr.Length-1; i++) { for (int j = i+1; j < arr.Length; j++) { if (arr[i] > arr[j]) //由大到小:arr[i] < arr[j] { int temp = arr[i]; arr[i] = arr[j]; arr[j] = temp; } } } } //遍历打印出数组 public static void PrintArray(int[] arr) { foreach (int pint in arr) { Console.WriteLine(pint); } } } } //测试类 using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace Cp4 { class Test { public static void Main(string[] agrs) { int[] a = {45,65,78,12,36}; SelectSorter.SelectSortAscending(a); //由于是静态方法,不用实例 SelectSorter.PrintArray(a); } } }