static void Main(string[] args) { int[] a = new int[8] { 9, 13, 24, 38, 23, 2, 43, 46 }; for (int i = 1; i <= a.Length - 1; i++) { for (int j = 1; j <= a.Length - i; j++) { if (a[j - 1] < a[j]) { int t = a[j - 1]; a[j - 1]= a[j] ; a[j] = t; } } } for (int k=0; k<= a.Length - 1;k++ ) { Console.WriteLine("遍历数组"+a[k]); } Console.ReadKey(); }
foreach(int k in a) { Console.WriteLine("遍历数组"+k); }