How to reverse a string in C#?

using System;

class Program
{
    static void Main()
    {
        string original = "Hello, World!";
        string reversed = ReverseString(original);

        Console.WriteLine("Original: " + original);
        Console.WriteLine("Reversed: " + reversed);
    }

    static string ReverseString(string str)
    {
        char[] reversedArray = new char[str.Length];
        for (int i = 0, j = str.Length - 1; i < str.Length; i++, j--)
        {
            reversedArray[i] = str[j];
        }
        return new string(reversedArray);
    }
}

 

Ebook Download
View all
Learn
View all
Creative Enterprizes s