![](https://i-blog.csdnimg.cn/blog_migrate/8f900a89c6347c561fdf2122f13be562.gif)
![](https://i-blog.csdnimg.cn/blog_migrate/961ddebeb323a10fe0623af514929fc1.gif)
using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace 实现字符串的返转 { class Program { static void Main(string[] args) { //把字符串先转换为一个字符数组 string s = "abcdehhhd"; char[] ct = s.ToCharArray(); for (int i = 0; i < ct.Length/2; i++) { //这里定义一个临时变量 其实就是通过引入第三个变量来交换两个值的意思 char temp = ct[i]; ct[i] = ct[ct.Length - i - 1]; ct[ct.Length - i - 1] = temp; } foreach (var VARIABLE in ct) { Console.WriteLine(VARIABLE); } Console.ReadKey(); } } }
以上就是反转字符串的第一版本C#