C# - String Reverse

C# - String Reverse in a Console Application

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace StringReverse
{
    class Program
    {
        static void Main(string[] args)
        {

            //Capture the input string
            Console.WriteLine("Enter the string that needs to be reversed : ");
            string input = Console.ReadLine();
           
            //This will remove all the spaces in between the words and arrange it into an array.
            string[] inputarray = input.Split(' ');
           
            //Declare a string array with length of newinput variable.
            string[] finalarray = new string[inputarray.Length];
           
            for (int i = 0; i < inputarray.Length; i++)
            {
                finalarray[(inputarray.Length - 1) - i] = inputarray[i];                   
            }
            //Console.WriteLine();

            foreach (string finalstring in finalarray)
            {
                Console.Write(finalstring + " ");
            }
            Console.ReadLine();
        }
    }
}

Output :
 

No comments: