Support us on YouTube by Subscribing our YouTube Channel. Click here to Subscribe our YouTube Channel

Monday 27 October 2014

Reverse a string in C#

In this Article, We will learn How to reverse a string using C#.

using System;

namespace reverseString
{
    class Program
    {
        static void Main(string[] args)
        {
            string str = "", reverse = "";
            int Length = 0;
            Console.WriteLine("Enter a Word");
            //Getting String(word) from Console
            str = Console.ReadLine();
            //Calculate length of string str
            Length = str.Length - 1;
            while(Length>=0)
            {
                reverse = reverse + str[Length];
                Length--;
            }
            //Displaying the reverse word
            Console.WriteLine("Reverse word is {0}",reverse);
            Console.ReadLine();
        }
    }
}
Preview:

Hope you like it. Thanks.
[Download Source Code via Google Drive]
Watch video:

0 comments:

Post a Comment

Subscribe us on YouTube

Subscribe Now

Popular Posts

Contact us

Name

Email *

Message *

Like us on Facebook