The Solution4:52 with James Churchill
In this video, we'll explain the solution to the challenge.
Welcome back, how did you do? 0:00 Don't worry if you ran into any issues, 0:03 it's completely natural to struggle when you're learning something new. 0:04 Let's walk through how I completed the session. 0:08 To create the new C# workspace I clicked on Workspaces in 0:12 the main menu of the Treehouse website. 0:16 Then here in the top left corner of the list of existing Workspaces, 0:22 I click the New link. 0:27 In the New Workspace dialogue, I enter the title C# practice session. 0:29 Selected C# for the environment. 0:37 And clicked Create Workspace. 0:42 Once the workspace finished loading, in the new window I selected the File, 0:47 New File menu item to add a new file. 0:51 And entered Program.cs for the file name. 0:57 I then went and grabbed a copy of the code from the teacher's notes for 1:04 the first video. 1:08 To do that I used the mouse to select the code, and pressed Ctrl+ C, or 1:10 Cmd+C on the Mac to copy the code to the clipboard. 1:14 I then use the mouse to click into the Program.cs file, and pressed Ctrl+ V, 1:23 or Cmd+ V on the Mac, to paste the code from the clipboard. 1:28 Don't forget to save the file at this point, you can do that by pressing 1:35 Ctrl+ S, or Cmd+ S on the Mac, or select the File, Save menu item. 1:38 Just as a quick review, our class is program, and 1:47 it's contains a single method named Main. 1:51 Remember that C# looks for a method named main when the program is ran. 1:56 The Main method contains a single line of code, which will write the text, 2:01 I love learning C# at Treehouse, to the console when we run the program. 2:06 Speaking of which, let's compile and run our program. 2:12 To start you need to make sure that the console is visible by selecting the View, 2:16 Show Console menu item. 2:21 If the console is currently being displayed, as it is for me, then you'll 2:25 see the menu item Hide Console, which allows you to hide the console. 2:30 To compile the program, I ran the command mcs Program.cs. 2:34 Be sure to capitalize the letter P, if you don't you'll receive an error from 2:43 the compiler that the file program.cs with a lower case p can't be found. 2:48 If the program was compiled successfully, the command will complete but 2:58 you won't see a message. 3:02 You can confirm that the command worked by running the ls command, 3:10 which will list the contents of the current folder. 3:14 We can see that our folder contains two files, Program.cs which is our code file, 3:18 and Program.exe, which is our program's compiled executable. 3:24 To run the program, I ran the command, mono Program.exe. 3:30 And here's the message, I love learning C# at Treehouse written to the console. 3:40 Again, if you're unable to get the program to run, 3:47 check to make sure you're typing the mono command in all lower case letters, and 3:50 that Program.exe starts with a capital P, and ends with .exe. 3:55 Doing any part of that incorrectly will result in an error. 4:01 Once you've gotten the program to run once, feel free to change the literal 4:06 string value that is being passed to the console write line method, 4:10 I love learning C# at Treehouse, to whatever you'd like. 4:14 Just be sure to recompile the program before you attempt to run it, 4:25 otherwise you'll still see the previous message written to the console. 4:29 And that's it. 4:44 Be sure to keep practicing, and 4:45 let us know if you'd like to see more of these practice sessions. 4:47 See you next time. 4:50
You need to sign up for Treehouse in order to download course files.Sign up