Skip to content

Commit

Permalink
Csharp Challenge 1 (YearOfProgramming#443)
Browse files Browse the repository at this point in the history
* [C#] Challenge 0 (Unreviewed)

* [C#] Challenge 1 (Unreviewed)
  • Loading branch information
jfrancis2 authored and erocs committed Jan 20, 2017
1 parent bb45f0a commit af73be1
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 0 deletions.
17 changes: 17 additions & 0 deletions challenge_1/csharp/jfrancis2/README.md
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
21 changes: 21 additions & 0 deletions challenge_1/csharp/jfrancis2/src/program.cs
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);
}
}
}

0 comments on commit af73be1

Please sign in to comment.