forked from YearOfProgramming/2017Challenges
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Csharp Challenge 1 (YearOfProgramming#443)
* [C#] Challenge 0 (Unreviewed) * [C#] Challenge 1 (Unreviewed)
- Loading branch information
Showing
2 changed files
with
38 additions
and
0 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
# Challenge 1 - Reverse a String | ||
###### C# | ||
|
||
### 1. Approach to Solving the problem | ||
|
||
I had to work out how to get a string, then make it backwards. Turns out there are inbuilt functions for this. | ||
|
||
### 2. How to compile and run this code | ||
|
||
From the /src directory, use `csc.exe program.cs` | ||
|
||
### 3. How this program works | ||
|
||
Takes a string from the console input | ||
Converts to a char array | ||
Uses the 'System.Reverse' function to change the order of the characters | ||
Displays the reversed string |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
using System; | ||
namespace YOP2017 | ||
{ | ||
class Program | ||
{ | ||
static void Main(string[] args) | ||
{ | ||
Console.WriteLine("Enter a string to reverse: "); | ||
string input = Console.ReadLine(); | ||
Console.WriteLine("Your string in reverse: " + Program.reverseString(input)); | ||
Console.WriteLine("Press any key to exit.") | ||
Console.ReadKey(true); | ||
} | ||
public static string reverseString(string input) | ||
{ | ||
char[] arr = input.ToCharArray(); | ||
Array.Reverse(arr); | ||
return new string(arr); | ||
} | ||
} | ||
} |