我正在尝试学习C#。我想输入一些文本,然后让它倒序输出。它确实对其进行了反转,但是会多次重复,次数与输入的文本长度相同。因此,hello变成了olleholleholleholleholleh。
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Reversed_Array
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Enter text to be reversed");
string inputText = Console.ReadLine();
char[] myChar = inputText.ToCharArray();
Array.Reverse(myChar);
foreach (char character in myChar)
{
Console.Write(myChar);
}
Console.ReadLine();
}
}
}
我想尝试将字符串转换为字符数组。我想提一下,因为我确实不需要字符数组。