;

C# Program to reverse a string


Tutorialsrack 30/04/2019 C# Programs

In this C# program, we will learn how to write a program to reverse a string.

Here is the Code of Program to reverse a string:

Code - C# Program To Reverse A String
using System;

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

Enter a String: Tutorialsrack

Reverse String is kcarslairotuT


Related Posts



Comments

Recent Posts
Tags