C# Program to display a string in reverse alphabetic order

CsharpProgrammingServer Side Programming

Set a string array and convert it to character array −

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

Now, use the Reverse method to display the above string in reverse alphabetic order −

Array.Reverse(arr);

Here is the complete code −

Example

 Live Demo

using System;
using System.Linq;
using System.IO;
class Program {
   static void Main() {
      string str = "Amit";
      char[] arr = str.ToCharArray();
      Console.WriteLine("Original String: "+str);
      // Reverse
      Array.Reverse(arr);
      Console.WriteLine("Reversed String: "+new string(arr));
   }
}

Output

Original String: Amit
Reversed String: timA
raja
Published on 05-Sep-2018 12:14:21
Advertisements