前几天去一家公司面试,遇到了一道题要求是反转字符串。不过不是很难。马上就做了出来
public static String ReverseString(String str)
{
if (string.IsNullOrEmpty(str))
{
throw new ArgumentException(str+"Error");
}
StringBuilder Sb = new StringBuilder(str.Length);
for (int index = str.Length-1; index >= 0; index--)
{
Sb.Append(str[index]);
}
return Sb.ToString();
}