C# Foundations

Lesson 2 of 6

Variables and Types

int xp = 100;
string name = "Ada";
bool isInstructor = true;
double score = 92.5;

Console.WriteLine($"{name} has {xp} XP");

Common types

TypeExample
int42
double3.14
string"hello"
booltrue / false

String interpolation

A $"..." string lets you embed expressions directly with { }, this is called string interpolation.

Type inference with var

var count = 10; // the compiler infers count is an int

var doesn't make C# dynamically typed, the compiler still figures out and locks in a concrete type at compile time, it just saves you from writing it out.

📝 Variables Quiz

Passing score: 70%
  1. 1.Which keyword lets the compiler infer a variable's type from its initial value?

  2. 2.Embedding expressions directly in a string with $"{name}" is called string ____.

  3. 3.Once a variable is declared as an int, you can later assign a string to it without casting or conversion.