c# · level 1 · unit 2 · lesson 1
- meet it
- guess first
- your turn
- fix it
- nailed it
Tap a green word if you get lost.
meet it
A ="button" class="pl-term" data-term="0" aria-expanded="false">variable is a box with a name on it.
A variable is a box your program keeps things in. You write a name on the label and put a inside. From then on, you say the name to get the value back.
In C# the label also says what kind of thing fits in the box. That is its type. string boxes hold text. boxes hold whole numbers, like 7 or 100.
So string name = "Sam"; means: make a string box called name and put "Sam" in it. To use the box, write its name with no quotes.
using System;
string name = "Sam";
int age = 9;
Console.WriteLine(name);
Console.WriteLine(age); Read the = as put into, not equals.
guess first
Quotes or no quotes? What will this show?
Guess before you run it. Wrong guesses are how you learn, and nothing is marked.
using System;
string pet = "Biscuit";
Console.WriteLine("pet");
Console.WriteLine(pet);
your turn
Your turn. Make up a superhero.
Name your superhero between the quotes on line 3. Give them a power level, a whole number, on line 4. Then press run.
output
press run to see what happens
fix it
The popcorn has gone missing. Can you fix it?
output
press run to see what happens
- Read the error. Which name does C# say does not exist?
- The box on line 3 is called snack. Compare it with the name on line 4, letter by letter.
- Change snak to snack on line 4, then press run.
nailed it
your program can remember things. :D
- A variable is a box with a name and a type.
stringboxes hold text.intboxes hold whole numbers.- Write the name with no quotes to get the value back.
new words in your collection
- variable
- value
- type
- int
This lesson isn’t saved. A free account remembers every lesson you finish.