Codeloft
0 0 XP

Variables and string interpolation

7 min 20 XP + 10 for no hints

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
  1. Change name to your own name
  2. Print the age with string interpolation, $"…{age}…"
  3. Add an if that checks age >= 18

Quick check

What does Console.WriteLine($"Hi {name}") print when name is "Ada"?

Program.csChecked as you type
No problems found. Unclosed tags, missing semicolons and errors show up here in plain words.