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:
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();
}
}
}
Enter a String: Tutorialsrack
Reverse String is kcarslairotuT
Comments