// (1)方法1 protected void Page_Load(object sender, EventArgs e) { string ss = ReverseStr(); Response.Write(ss); } //1.逆序一个字符串 public string ReverseStr() { string s1 = ""; string Str = "ABCDEFG"; for (int i = Str.Length; 0 < i; i--) { s1 += Str.Substring(i - 1, 1); } return s1; } //(2)方法2 public void ReverseStr() { string Str = "ABCDEFG"; Char[] MyChar = Str.ToCharArray(); Array.Reverse(MyChar); string MyStr = new string(MyChar); Response.Write(MyStr); } //方法3 protected void Page_Load(object sender, EventArgs e) { string ss = Reverse("ABCDEFG"); Response.Write(ss); //ReverseStr(); } public static string Reverse(string str) { if (string.IsNullOrEmpty(str)) { throw new ArgumentException("参数不合法"); } char[] chars = str.ToCharArray(); int begin = 0; int end = chars.Length - 1; char tempChar; while (begin < end) { tempChar = chars[begin]; chars[begin] = chars[end]; chars[end] = tempChar; begin++; end--; } string strResult = new string(chars); return strResult; }