This article illustrates the different techniques to efficiently create a reverse copy of a string in C#.

1. Using Array.Reverse() method

We can use Array.reverse() to create a reverse copy of a string in C#. The idea is to convert the given string into a character array using the String.toCharArray() method, and reverse the array using the Array.Reverse() method. Then, convert the character array back into a string using the String constructor and return it. The following program demonstrates it:

Download  Run Code

2. Using String.Create() method

Starting with .NET 6, you can use the String.Create() method to reverse a string. It creates a new string with a specific length and initializes it after creation by using the specified callback. The following example demonstrates its usage:

Download  Run Code

That’s all about efficiently creating a reverse copy of a string in C#.