您的位置:首页 > 产品设计 > UI/UE

实验StringBuilder类实现字符反转

2016-03-18 17:04 447 查看
如题:

(1)将String转换成Char;

(2)使用StringBuilder类

代码如下:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
string  x = Console.ReadLine();
Console.WriteLine(Reverse(x));
Console.ReadKey();
}
public static string Reverse(String str)
{
StringBuilder strBu = new StringBuilder();
char[] c=str.ToCharArray();

for (int i = 0; i <c.Length; i++)
{
strBu.Append(c[c.Length-i-1]);
}
return strBu.ToString();
}

}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: