Skip to content

Instantly share code, notes, and snippets.

@spoon16
Forked from blaineh/ReverseHW C#
Created October 22, 2011 21:03
Show Gist options
  • Save spoon16/1306490 to your computer and use it in GitHub Desktop.
Save spoon16/1306490 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();
}
// THIS method is what they will want to see on the whiteboard if they ask you a question like this
// this is not a datastructure question it's an algorithm question which means they just want to
// see the method
static string reverseString(string original)
{
char[] array = original.ToCharArray();
//create for loop
for (int i = 0; i < (original.Length / 2); i++)
{
int j = original.Length - 1 - i;
char temp = array[i];
array[i] = array[j];
array[j] = temp;
}
//return char array as string
return new String(array);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment