Skip to content

Instantly share code, notes, and snippets.

@TonnyXu
Created February 27, 2010 06:51
Show Gist options
  • Save TonnyXu/316527 to your computer and use it in GitHub Desktop.
Save TonnyXu/316527 to your computer and use it in GitHub Desktop.
public static string reverseByArray(string input)
{
if (string.IsNullOrEmpty(input)) return input;
int halfLength = input.Length >> 1;
char[] inputArray = input.ToCharArray();
char temp;
for (int i = 0; i < halfLength; i++)
{
temp = inputArray[i];
inputArray[i] = inputArray[input.Length - i - 1];
inputArray[input.Length - i - 1] = temp;
}
return new string(inputArray);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment