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();
- }
Take two strings. One as the input string that accepts a string from the user, and the second string is used to store the string in reverse order. For loop is used to traverse the string length and append each character to the reverse string.
Output