How to reverse a string without using Reverse() method in C#

1 Answer

0 votes
using System;

class Program {
   static string reverse(string str) {
        string reversedString = "";
   
        for (int i = str.Length - 1; i >= 0; i--) {
            reversedString += str[i];
        }
        
        return reversedString;
   }
   
   static void Main(string[] args) {
        string str = "c# c c++ java python";
      
        str = reverse(str);
        
        Console.WriteLine(str);
   }
}



/*
run:
   
nohtyp avaj ++c c #c
   
*/

 



answered Apr 7, 2024 by avibootz
...