string[] s = { "a", "b", "c", "d" }; List<string> list = new List<string>(); for (int i = s.GetLength(0) - 1; i >= 0; i--) { list.Add(s[i]); } s = list.ToArray();
用linq写:s = s.Reverse().ToArray();
string[] str = { "a", "b", "c", "d" }; string[] str2 = new string[4]; for (int i = 0; i < str.Length; i++) { str2[i] = str[(str.Length - 1) - i]; Console.WriteLine("{0}", str2[i]); } //string[] name = { "a", "b", "c", "d" }; //for (int i = 0; i < name.Length / 2; i++) //{ // string temp = name[i]; // name[i] = name[name.Length - 1 - i]; // name[name.Length - 1 - i] = temp; //} //for (int i = 0; i < name.Length; i++) //{ // Console.WriteLine(name[i]); //}
char[] a = { 'a', 'b', 'c', 'd','e' }; char b; int len = a.Length; for (int i = 0; i < len / 2; i++) { b = a[i]; a[i] = a[len - i - 1]; a[len - i - 1] = b; }
List<string> list = new List<string>();
for (int i = s.GetLength(0) - 1; i >= 0; i--)
{
list.Add(s[i]);
}
s = list.ToArray();
string[] str = { "a", "b", "c", "d" };
string[] str2 = new string[4];
for (int i = 0; i < str.Length; i++)
{
str2[i] = str[(str.Length - 1) - i];
Console.WriteLine("{0}", str2[i]);
} //string[] name = { "a", "b", "c", "d" };
//for (int i = 0; i < name.Length / 2; i++)
//{
// string temp = name[i];
// name[i] = name[name.Length - 1 - i];
// name[name.Length - 1 - i] = temp;
//}
//for (int i = 0; i < name.Length; i++)
//{
// Console.WriteLine(name[i]);
//}
string txt = "abcda";
string rslt = string.Join("", txt.Reverse()).ToString();
Console.Write(rslt);
string[] txt = { "a","b","c","d","a"};
string rslt = string.Join("", txt.Reverse());
Console.Write(rslt);
txt = txt.Reverse().ToArray();
char b;
int len = a.Length;
for (int i = 0; i < len / 2; i++)
{
b = a[i];
a[i] = a[len - i - 1];
a[len - i - 1] = b;
}