(C#)字符串反转
2021-03-24 00:23
标签:net new for build exception eve name stat turn 方法一: public static string Reverse(string name) 方法二:.NET3.5以上 public static string Reverse(string name) return new string(reverse); 方法三:二分法 public static string Reverse(string name) return new string(nm); } (C#)字符串反转 标签:net new for build exception eve name stat turn 原文地址:https://www.cnblogs.com/Connaughtyu/p/9448157.html
{
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();
}
{
char[] reverse = name.Reverse().ToArray();
}
{
if (String.IsNullOrEmpty(name))
{
throw new Exception("字符串不能为空!");
}
char[] nm = name.ToCharArray();
for (int i = 0; i {
char q = nm[i];
nm[i]= nm[nm.Length - 1 - i];
nm[nm.Length - 1 - i] = q;
}
上一篇:https