static string ReverseString(string str)
{
if (str == null || str.Length <= 1)
{
return str;
}
string result = "";
for (int i = str.Length - 1; i >= 0; i--)
{
result += str[i];
}
return result;
}
static string ReverseString2(string str)
{
if (str == null || str.Length <= 1)
{
return str;
}
StringBuilder sb = new StringBuilder();
for (int i = str.Length - 1; i >= 0; i--)
{
sb.Append(str[i]);
}
return sb.ToString();
}
static string ReverseString3(string str)
{
if (str == null || str.Length <= 1)
{
return str;
}
char[] charArray = str.ToCharArray();
for (int i = 0; i < charArray.Length / 2; i++)
{
char temp = charArray[i];
charArray[i] = charArray[charArray.Length - i - 1];
charArray[charArray.Length - i - 1] = temp;
}
return new string(charArray);
}