C#将一个字符串数组的元素的顺序进行反转
1 //将一个字符串数组的元素的顺序进行反转。 2 3 //{“A”,“B”,”C”,"D","E","F"} {“F”,”E”,”D”,“C”,“B”,”A”}。第i个和第length-i-1个进行交换。 4 5 //i Length-1-0 6 7 //i+1 Leng-1-1 8 9 //i+2 Leng-1-2 10 11 12 13 string[] names = { "a", "b", "c", "d", "e", "f", "g" }; 14 for (int i = 0; i < names.Length / 2; i++) 15 { 16 string temp = names[i]; 17 names[i] = names[names.Length - 1 - i]; 18 names[names.Length - 1 - i] = temp; 19 } 20 21 for (int i = 0; i < names.Length; i++) 22 { 23 Console.WriteLine(names[i]); 24 } 25 Console.ReadKey(); 26 27