using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Demo
{
class Program
{
static void Main(string[] args)
{
string s = "This is a test.";
Console.WriteLine("Before: " + s);
RevStr r = new RevStr();
r.DisplayRev(s);
Console.WriteLine("After: " + r.ReturnString);
//Array.Reverse(s.ToCharArray()); //使用Array.Reverse方法进行字符串反转
Console.ReadKey();
}
}
class RevStr
{
string returnString = string.Empty;
/// <summary>
/// 反转之后的字符串
/// </summary>
public string ReturnString
{
get { return returnString; }
}
public void DisplayRev(string str)
{
if (str.Length > 0)
{
DisplayRev(str.Substring(1, str.Length - 1));
if (returnString == string.Empty)
returnString = str[0].ToString();
else
returnString += str[0].ToString();
}
}
}
}
C#反转字符串
最新推荐文章于 2023-09-22 19:22:48 发布