EN
C# / .NET - how to reverse a string
0
points
In this article, we would like to show you how to reverse a string in C#.
Practical example
In the example below, we use the Array.Reverse()
method, which argument is a string converted into an array of characters.
using System;
public class Program
{
static string ReverseString(string originalString)
{
char[] charArray = originalString.ToCharArray();
Array.Reverse(charArray);
return new string(charArray);
}
public static void Main(string[] args)
{
string originalString = "This is your text...";
string reversedString = ReverseString(originalString);
Console.WriteLine(reversedString); // ...txet ruoy si sihT
}
}
Output:
...txet ym si sihT