Created
October 22, 2011 20:20
-
-
Save blaineh/1306452 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(); | |
} | |
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