Variables and Types
int xp = 100;
string name = "Ada";
bool isInstructor = true;
double score = 92.5;
Console.WriteLine($"{name} has {xp} XP");
Common types
| Type | Example |
|---|---|
int | 42 |
double | 3.14 |
string | "hello" |
bool | true / 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.