目的:将字串"I am a programmer"完全反转为"remmargorp a ma I"。
方法一:
private static void reverse()
{
string str = "I am a programmer";
for (int i = str.Length -1; i >=0; i--)
{
Console.Write(str[i]);
}
Console.WriteLine();
}
方法二:
private static void reverse()
{
string str = "I am a programmer";
char[] arr = new char[str.Length];
for (int i = 0; i < str.Length; i++)
{
arr[i] = str[i];
}
Array.Reverse(arr);
for (int j = 0; j < arr.Length; j++)
{
Console.Write(arr[j]);
}
Console.WriteLine();
}