C# Program to Reverse a string in csharp.net
C# Program to Reverse a string in csharp.net
- Start Visual Studio and select File -- New project
- From the project dialog, select the Console application
- In the Console Application in Program.cs File write the below program to reverse a string in (c#)csharp .net
- In this reverse string program in csharp we are taking a string as user input
- After taking the user input string we are looping using for loop for string.length times and appending the reverse string to a string variable and finally we are displaying the output
- you can refer below program for code and with live demo and output
using System;
namespace ReverseSample
{
class StringReverse
{
public static void Main()
{
string Str, Revstr = "";
Console.Write("Enter A String : ");
Str = Console.ReadLine();
for (int i = Str.Length - 1; i >= 0; i--)
{
Revstr = Revstr + Str[i];
}
Console.WriteLine("Reverse String Is {0}", Revstr);
Console.ReadLine();
}
}
}
After writing this program hit F5 .you will see a black window .program running Output:-
Enter A String : ABC
Reverse String Is: CBA
Live Demo
0 comments:
Post a Comment