Reverse String Program in C#


Prev Tutorial Next Tutorial

Reverse a String Program in C#

To reverse any string we no need any new concept just apply same concept like C and C++ Program.

Formula

Remainder = Number % 10;  
Reverse = (Reverse * 10) + remainder;  
Number = Number / 10; 

Reverse a String Program in C#

using System;  
  
namespace reverseString  
{  
class Program  
{  
static void Main(string[] args)  
{  
string str = "", reverse = "";  
int Length = 0;  
Console.WriteLine("Enter any String: ");  
//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 string  
Console.WriteLine("Reverse String is: {0}",reverse);  
Console.ReadLine();  
 }  
}  
}

Output

Enter any String: Raj
Reverse String is: jaR

Output

Enter any String: Hitesh
Reverse String is: hsetiH

Prev Tutorial Next Tutorial

Google Advertisements
Download Projects

Google Adsense Advertisements

Buy 3 Year Old Domain, Tutorialday.com, SeosmoTools.com @$200

Buy This Ad Space @$50 per Month, Ad Size 300X250 Contact on: hitesh.xc@gmail.com WhatsApp no. 8882538826

Yahoo Advertisements