Home >Backend Development >C#.Net Tutorial >How to reverse a string using C#?

How to reverse a string using C#?

王林
王林forward
2023-08-22 23:09:081729browse

How to reverse a string using C#?

To reverse a string, use the Array.Reverse() method.

Set the string to be reversed −

string str = "Amit";

In the above method, we convert the string into a character array −

char[] ch = str.ToCharArray();

and then use the Reverse() method. The Chinese translation of

Array.Reverse(ch);

Example

is:

Example

using System;
namespace Demo {
   class Program {
      static void Main(string[] args) {

         string str = "Amit";
         char[] ch = str.ToCharArray();

         Array.Reverse(ch);

         foreach(var items in ch) {
            Console.WriteLine(items);
         }

         Console.ReadLine();
      }
   }
}

The above is the detailed content of How to reverse a string using C#?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:tutorialspoint.com. If there is any infringement, please contact admin@php.cn delete