How to reverse a String using C#?

In C# there are multiple ways to reverse a string. The most common approach is using the Array.Reverse() method, but you can also use other techniques like loops or LINQ methods for different scenarios.

Using Array.Reverse() Method

The Array.Reverse() method is the most efficient way to reverse a string. First, convert the string to a character array, then apply the reverse method −

using System;

class Program {
    static void Main(string[] args) {
        string str = "Amit";
        char[] ch = str.ToCharArray();
        
        Array.Reverse(ch);
        
        string reversedStr = new string(ch);
        Console.WriteLine("Original: " + str);
        Console.WriteLine("Reversed: " + reversedStr);
    }
}

The output of the above code is −

Original: Amit
Reversed: timA

Using For Loop

You can also reverse a string by iterating through characters in reverse order and building a new string −

using System;

class Program {
    static void Main(string[] args) {
        string str = "Hello World";
        string reversed = "";
        
        for (int i = str.Length - 1; i >= 0; i--) {
            reversed += str[i];
        }
        
        Console.WriteLine("Original: " + str);
        Console.WriteLine("Reversed: " + reversed);
    }
}

The output of the above code is −

Original: Hello World
Reversed: dlroW olleH

Using LINQ Reverse() Method

LINQ provides a Reverse() extension method that can be applied to any enumerable collection, including strings −

using System;
using System.Linq;

class Program {
    static void Main(string[] args) {
        string str = "Programming";
        string reversed = new string(str.Reverse().ToArray());
        
        Console.WriteLine("Original: " + str);
        Console.WriteLine("Reversed: " + reversed);
    }
}

The output of the above code is −

Original: Programming
Reversed: gnimmargorP

Comparison of Methods

Method Performance Use Case
Array.Reverse() Most efficient Best for simple string reversal
For Loop Good performance When you need custom logic during reversal
LINQ Reverse() Slightly slower When working with functional programming style

Conclusion

The Array.Reverse() method is the most efficient approach for reversing strings in C#. For simple reversals, convert the string to a character array, apply Array.Reverse(), and create a new string from the result.

Updated on: 2026-03-17T07:04:35+05:30

754 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements