请问下面这程序用C#怎么写啊?
来源:百度知道 编辑:UC知道 时间:2024/07/05 15:47:56
请高手们教教我这个菜鸟吧~跪谢~!
static void Main(string[] args)
{
Console.WriteLine("请输入一个字符串,将会反序输出:");
string ReadString=Console.ReadLine();
char[] strchar = ReadString.ToCharArray();
for (int index = strchar.Length - 1; index >= 0; index--)
{
Console.Write(strchar[index]);
}
Console.ReadLine();
}
C#裏字符串有个reverse方法好像直接能输出逆序
用readline来接收输入的字串
用writeline输出字串
public string backString(string str){
string result="";
for(int ii=str.Length-1;ii>=0;ii--){
result+=str.Substring(ii,1);//将字符串反向累加
}
return result;
}
在你需要操作的地方.调用这个方法就OK.比如:
string str="abcdefg";
string newstr=backString(str);
此时newstr的值为:gfedcba
string x=Console.ReadLine();
char[] c=x.ToCharArray();
Array.Reverse(c);//反响排序