C#将一个字符串数组的元素的顺序进行反转
作者:互联网
//将一个字符串数组的元素的顺序进行反转。
//{“A”,“B”,”C”,"D","E","F"} {“F”,”E”,”D”,“C”,“B”,”A”}。第i个和第length-i-1个进行交换。
//i Length-1-0
//i+1 Leng-1-1
//i+2 Leng-1-2
string[] names = { "a", "b", "c", "d", "e", "f", "g" };
for (int i = 0; i < names.Length / 2; i++)
{
string temp = names[i];
names[i] = names[names.Length - 1 - i];
names[names.Length - 1 - i] = temp;
}
for (int i = 0; i < names.Length; i++)
{
Console.WriteLine(names[i]);
}
Console.ReadKey();
标签:Leng,string,temp,C#,int,Length,names,数组,字符串 来源: https://www.cnblogs.com/momj/p/14273747.html