How to Reverse a String in C#/CSharp

To reverse a string in C#/CSharp, we first convert string to an array of characters.  Then, use static method Reverse which resides in Array class to reverse the string.  Example is given below.

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
using System;
using System.IO;
namespace Hello_World
{
class Program
{
static void Main(string[] args)
{
string hello = "Hello World";
char[] array = hello.ToCharArray();
Array.Reverse(array);
Console.WriteLine(array);
}
}
}
using System; using System.IO; namespace Hello_World { class Program { static void Main(string[] args) { string hello = "Hello World"; char[] array = hello.ToCharArray(); Array.Reverse(array); Console.WriteLine(array); } } }
using System;
using System.IO;

namespace Hello_World
{

    class Program
    {
        static void Main(string[] args)
        {
            string hello = "Hello World";

            char[] array = hello.ToCharArray();
            Array.Reverse(array);

            Console.WriteLine(array);
        }               
    }
}