前几天,在网上看了一个很好,很简洁的C#倒转字符串的例子,很好,很方便,就记下来了.兴许以后面试用的上,呵呵.
using System;
using System.Collections.Generic;
using System.Text;
namespace ReverseString
{
public class Program
{
static void Main(string[] args)
{
string str;
Console.WriteLine("Please input some string:");
str = Console.ReadLine();
str = ReversString(str);
Console.WriteLine("Now the string of your input is: {0}", str);
Console.ReadLine();
}
private static string ReversString(string str)
{
char[] arr = str.ToCharArray();
Array.Reverse(arr);
str = new string(arr);
return str;
}
}
}