You are viewing a free preview of this lesson.
Subscribe to unlock all 10 lessons in this course and every other course on LearningBro.
C# is a statically typed language — every variable has a type known at compile time. This lesson covers the type system, value types, reference types, strings, and nullable types.
Variables in C# are declared with a type followed by a name:
int age = 30;
string name = "Alice";
double price = 19.99;
bool isActive = true;
The var keyword lets the compiler infer the type from the assigned value:
var age = 30; // int
var name = "Alice"; // string
var price = 19.99; // double
var isActive = true; // bool
Tip: Use
varwhen the type is obvious from the right-hand side. Use explicit types when clarity is needed.
| Category | Stored In | Assignment | Default | Examples |
|---|---|---|---|---|
| Value types | Stack | Copies the value | 0, false, etc. | int, double, bool, struct, enum |
| Reference types | Heap | Copies the reference | null | string, class, array, object |
Subscribe to continue reading
Get full access to this lesson and all 10 lessons in this course.