日期:2014-05-18 浏览次数:21025 次
public static class StringPlus { public static string Reverse(this string s) { return ReverseOlder(s); } public static string ReverseOlder(string s) { string ret = ""; for (int i = s.Length - 1; i >= 0; i--) { ret += s[i]; } return ret; } } class Program { static void Main(string[] args) { int a = 123; //C# 3.0 扩展方法的写法 Console.WriteLine(a.ToString().Reverse()); //C# 2.0 普通的写法 Console.WriteLine(StringPlus.ReverseOlder(a.ToString())); Console.ReadKey(); } }