Heads up! To view this whole video, sign in with your Courses account or enroll in your free 7-day trial. Sign In Enroll
Preview
Start a free Courses trial
to watch this video
In this video, we'll explain the challenge that you'll be working to complete.
Prerequisites
This practice session assumes that you've completed stage 2 of the C# Basics course. If you haven't done that yet, go check it out, then come back to this workshop.
Help
If you get stuck on any of the following topics or simply need a refresher, click on a topic in list below to view the associated video in the C# Basics course.
[MUSIC]
0:00
Hi everyone, this is James.
0:04
In this C# practice session, you'll get a
chance to practice declaring and assigning
0:07
variables, capturing user input and
writing output to the console using C#.
0:12
It reinforces what you learned in
stage two of the C# basics course.
0:17
If you find this practice
session too difficult,
0:22
you might need to review that course.
0:25
See the teacher's notes for a link.
0:27
I've attached a workspace to this video.
0:29
Go ahead and open the workspace or
download the project files if you want
0:32
to use an external editor or
IDE like Visual Studio.
0:36
The Program.cs file contains a single
method named main which will contain all
0:46
of the code for your program.
0:51
In order to complete
this practice session,
0:55
you'll read through these to do code
comments and complete each one.
0:57
The purpose of this program is to
ask the user for their name and
1:05
their favorite movie.
1:09
Or book, city, car, food,
whatever you'd like.
1:11
Let's see the completed program in action.
1:16
We'll compile our program
using the mcs command.
1:19
And run the program
using the mono command.
1:22
The program prompts me for my name.
1:32
Then my favorite movie.
1:35
And then, outputs my name and
favorite movie to the console.
1:40
There are four tasks that you'll
need to complete in this session.
1:49
Each task is described
in a TODO code comment.
1:52
Let's review them now.
1:56
For the first TODO, you need to declare
a variable named thing and assign it to
1:57
a string literal representing the thing
that you'll be asking the user for.
2:02
I'm going to use movie for my thing,
but you could use whatever you'd like.
2:06
For the second TODO, you need to
prompt the user for their name and
2:12
assign their provided value into
a string variable named name.
2:16
For the third TODO,
you'll prompt the user again.
2:20
This time for their favorite thing.
2:23
You can use string concatenation
to combine the thing variable
2:25
with the string literal,
what is your favorite thing?
2:29
Then assign the user's provided value to
a string variable named favorite thing.
2:32
Then, for the fourth and last TODO,
output the user's name and
2:38
favorite thing to the console.
2:42
For example, my name is James, and
my favorite movie is Toy Story.
2:44
But you can format the output
however you'd like.
2:48
When writing output to the console,
be sure to play around with the difference
2:52
between the console write and
the writeline methods.
2:56
You'll find each method to be helpful for
different situations.
2:59
Practice is an important part
of the learning process.
3:03
Doing it will help you to
retain what you've learned.
3:06
If you get stuck at any point, see
the teacher's notes for hints and links to
3:10
videos that'll cover what you need to
know in order to complete this session.
3:13
And if you can't quite get it right,
don't worry,
3:18
I'll show you how to complete
the TODOs in the next video.
3:21
Good luck and we'll see you in a bit.
3:25
You need to sign up for Treehouse in order to download course files.
Sign up