Skip to content

Instantly share code, notes, and snippets.

@blaineh
Created October 22, 2011 20:20
Show Gist options
  • Save blaineh/1306452 to your computer and use it in GitHub Desktop.
Save blaineh/1306452 to your computer and use it in GitHub Desktop.
Reverse Hello world C#
//namespace names this object.
namespace blaine
{
class helloworld
{
//Every program starts with a Main method.
//Static indicates that you can access this method without having an object of your class available.
//void indicates to the compiler that your method will not return a value to the calling method.
static void Main()
{
System.Console.WriteLine(reverseString("Hello"));
System.Console.ReadKey();
}
static string reverseString(string original)
{
int cnt = (int)(original.Length / 2);
char[] array = original.ToCharArray();
//create for loop
for (int i = 0; i < cnt; i++)
{
int j = original.Length - 1 - i;
char temp = array[i];
array[i] = array[j];
array[j] = temp;
}
//store char array as string
original = new string(array);
System.Console.WriteLine(cnt);
return original;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment