Wednesday, 14 October 2015

Reverse a string without using function in C#

using System;
class Program
    {
        public static void Main(string[] args)
        {
            string reverse = null;
            int length;
            Console.WriteLine("Please enter a word for reverse");
            string str = Console.ReadLine();
            length = str.Length-1;
            while (length >= 0)
            {
                reverse = reverse + str[length];
                length--;
            }
            Console.WriteLine("reverse word of {0}  is : {1}", str, reverse);
        }
    }

No comments:

Post a Comment