反转一个字符串

C# codes as below:

public static string TheMethod(string str)

{

if(str == string.Empty)

{

return string.Empty;

}

char[] charArray = str.ToCharArray();

int i = 0;

while (i < str.Length - 1 - i)

{

char reserveChar = charArray[i];

charArray[i] = charArray[str.Length - 1 - i];

charArray[str.Length - 1 - i] = reserveChar;

i++;

}

return new string(charArray);

}

你可能感兴趣的:(字符串)