LeetBook 反转字符串

C#

static void Main(string[] args)
{
string[] s =new string[4] { "a", "b", "c", "d" };

ReverseString(s);

Console.ReadLine();
}

///


/// 反转字符串数组
///

///
private static void ReverseString(string[] s)
{
string firstNumber = string.Empty;
for (int i = 0; i < s.Length / 2; i++)
{
firstNumber = s[i];

//首尾交换
s[i] = s[s.Length - 1 - i];
s[s.Length - 1 - i] = firstNumber;
}

for (int i = 0; i < s.Length; i++)
{
Console.WriteLine(s[i]);
}
}

posted @ 2022-07-11 13:48  江宁织造  阅读(45)  评论(0)    收藏  举报