top of page

C Sharp

Public·2 members

Reverse a String Using for Loop

Let us proceed and create a sample program to understand the logic to implement the same.

Write the below code in a console application.



  static void Main(string[] args)  {    
  string _Inputstr = string.Empty, _Reversestr = string.Empty;     
  Console.Write("Enter the string : ");    
  _Inputstr = Console.ReadLine();    
  for (inti = _Inputstr.Length - 1; i >= 0; i--)   
   {    
      _Reversestr += _Inputstr[i];    
   }   
   Console.WriteLine("The reverse string is {0}", _Reversestr); 
   Console.ReadLine();  }      

Output:
Enter the string :  susheel
The reverse string is  leehsus

38 Views
bottom of page