Skip to content

Instantly share code, notes, and snippets.

@akhanalcs
Created July 31, 2017 18:40
Show Gist options
  • Save akhanalcs/d25ade1ad41b889bee06f55e7d8c074f to your computer and use it in GitHub Desktop.
Save akhanalcs/d25ade1ad41b889bee06f55e7d8c074f to your computer and use it in GitHub Desktop.
A simple C# program to reverse a string
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