Introducing Radical.sh

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

Reverse a string using FOR loop in C#

Using for loop we can reverse a string with char array reversing.

  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[] cArray = name.ToCharArray();
  12. string nameReverse = String.Empty;
  13. for (int i = cArray.Length - 1; i > -1; i--)
  14. {
  15. nameReverse += cArray[i];
  16. }
  17. Console.WriteLine(nameReverse);
  18. }
  19. }
  20. }


Output:

Enter the string to reverse :
forget code

edoc tegrof