C# 反转字符串

时间:2023-03-09 19:58:07
C# 反转字符串
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();
            ; i < ct.Length/; i++)
            {
                //这里定义一个临时变量 其实就是通过引入第三个变量来交换两个值的意思
                char temp = ct[i];
                ct[i] = ct[ct.Length - i - ];
                ct[ct.Length - i - ] = temp;

            }
            foreach (var VARIABLE in ct)
            {
              Console.WriteLine(VARIABLE);
            }
            Console.ReadKey();
        }
    }
}

以上就是反转字符串的第一版本C#