Friday, 4 July 2014

Reverese the String in C# Console Application



Reverese the String in C# Console Application

Descriptions: Here, I will write a simple program in c# to reverse the String.


static void Main(string[] args)
        {
            //for storing string value
            string Str, Revstr = string.Empty;
            //for counting lenght of given string
            int Length;

            //showing message to user
            Console.Write("Enter String : ");
            //to allow user to input string
            Str = Console.ReadLine();

            //storing the length of given string
            Length = Str.Length - 1;

            //loops the given string length
            while (Length >= 0)
            {
                //performimg a reverse string according to length of given string
                Revstr = Revstr + Str[Length];
                Length--;
            }
            // displaying output to user
            Console.WriteLine("Reverse  String  Is  {0}", Revstr);
            // to keep window
            Console.ReadLine();
        }

No comments:

Post a Comment