CSharp - Write program to reverse a string

Requirements

Write program to reverse a string

Hint

We will put string elements into a character array and then we traverse the array from the opposite direction.

Demo

using System;
using System.Linq;

public class MainClass
{
    public static void Main(String[] argv)
    {/*from w  ww .j  a  v  a2  s  .  co m*/
        Console.WriteLine("Enter a string");
        string inputString = Console.ReadLine();
        char[] tempArray = inputString.ToArray();
        string outputString = String.Empty;
        for (int i = tempArray.Length - 1; i >= 0; i--)
        {
            outputString = outputString + tempArray[i];
        }
        Console.WriteLine("Reversed string is {0}", outputString);
    }
}

Result