Created
July 31, 2017 18:40
-
-
Save akhanalcs/d25ade1ad41b889bee06f55e7d8c074f to your computer and use it in GitHub Desktop.
A simple C# program to reverse a string
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
namespace Reverse | |
{ | |
class Program | |
{ | |
static void Main(string[] args) | |
{ | |
Console.WriteLine("Enter a number or a string"); | |
string s = Console.ReadLine(); | |
Program p = new Program(); | |
string t = p.Reverse(s); | |
Console.WriteLine("The reverse of {0} is {1}", s, t); | |
} | |
public string Reverse(string str) | |
{ | |
char[] cArray = str.ToCharArray(); | |
string reverse = ""; | |
for (int i = cArray.Length-1; i >-1; i--) | |
{ | |
reverse += cArray[i]; | |
} | |
return reverse; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment