Introducing Radical.sh

Forget Code launches a powerful code generator for building API's

Reverse a string in C#

We can reverse the characters of a string like below.
String is converted to char array after that reverse operation will happen.

  1. using System;
  2. namespace forgetCode
  3. {
  4. class Program
  5. {
  6. public static void Main(string[] args)
  7. {
  8. Console.WriteLine("Enter the string to reverse :");
  9. string name = Console.ReadLine();
  10.  
  11. char[] namesArray = name.ToCharArray();
  12. Array.Reverse(namesArray);
  13.  
  14. string nameReverse = new string(namesArray);
  15.  
  16. Console.WriteLine(nameReverse);
  17.  
  18. }
  19. }
  20. }


Output:

Enter the string to reverse :
forget code

edoc tegrof


..