-
-
Save spoon16/1306490 to your computer and use it in GitHub Desktop.
Reverse Hello world C#
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
//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