标签:net new for build exception eve name stat turn
方法一:
public static string Reverse(string name)
{
if (String.IsNullOrEmpty(name))
{
throw new Exception("字符串不能为空!");
}
StringBuilder sb = new StringBuilder(name.Length);
for (int i = name.Length-1; i >= 0; i--)
{
sb.Append(name[i]);
}
return sb.ToString();
}
方法二:.NET3.5以上
public static string Reverse(string name)
{
char[] reverse = name.Reverse().ToArray();
return new string(reverse);
}
方法三:二分法
public static string Reverse(string name)
{
if (String.IsNullOrEmpty(name))
{
throw new Exception("字符串不能为空!");
}
char[] nm = name.ToCharArray();
for (int i = 0; i < (nm.Length-1 )/ 2; i++)
{
char q = nm[i];
nm[i]= nm[nm.Length - 1 - i];
nm[nm.Length - 1 - i] = q;
}
return new string(nm);
}
标签:net new for build exception eve name stat turn
原文地址:https://www.cnblogs.com/Connaughtyu/p/9448157.html