Variables and string interpolation
C# variables have types: string for text, int for whole numbers, bool for true or false.
String interpolation puts values into text. Start the string with $ and wrap names in braces: $"Age: {age}".
An if statement runs code only when a condition is true, like if (age >= 18).
Example (inside Main)
string city = "Oslo";
int temp = -3;
Console.WriteLine($"It is {temp} degrees in {city}");
Output
It is -3 degrees in Oslo
Without the
$, C# prints the braces literally: Age: {age}.Your tasks
0 of 3 done- Change name to your own name
- Print the age with string interpolation, $"…{age}…"
- Add an if that checks age >= 18
Tutor
The tutor guides you toward the answer instead of handing it over. It uses your own Claude usage.
Quick check
What does Console.WriteLine($"Hi {name}") print when name is "Ada"?
No problems found. Unclosed tags, missing semicolons and errors show up here in plain words.
1using System;
2
3class Program
4{
5 static void Main()
6 {
7 string name = "Sam";
8 int age = 21;
9 Console.WriteLine($"Name: {name}");
10 if (age >= 18)
11 {
12 Console.WriteLine("You can vote.");
13 }
14 }
15}
A string variable called name holds the text "Sam".
Variables
| name | "Sam" |
Output
Step 1 of 6