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#.
In the example below, we use the Array.Reverse()
method, which argument is a string converted into an array of characters.
xxxxxxxxxx
1
using System;
2
3
public class Program
4
{
5
static string ReverseString(string originalString)
6
{
7
char[] charArray = originalString.ToCharArray();
8
Array.Reverse(charArray);
9
return new string(charArray);
10
}
11
12
public static void Main(string[] args)
13
{
14
string originalString = "This is your text...";
15
16
string reversedString = ReverseString(originalString);
17
Console.WriteLine(reversedString); // ...txet ruoy si sihT
18
}
19
}
Output:
xxxxxxxxxx
1
...txet ym si sihT