Every great architect needs a well-organized workshop. Imagine walking into yours for the first time — shelves lined with labeled boxes, each one holding a specific kind of material. One box is labeled "Project Name" and holds text. Another says "Floor Count" and holds a whole number. A third reads "Budget Approved" and holds a simple yes or no.
That's exactly what variables are in C#. They are named containers that store a specific type of data. The label is the variable name, and the box's shape determines what kind of data fits inside.
C# is a statically-typed language, which means you must tell it what kind of box you want before you put anything in it. Here are the five fundamental types every .NET Architect reaches for first:
int — Whole numbers (e.g., floors in a building): int floors = 25;double — Decimal numbers (e.g., height in meters): double height = 5.9;string — Text (e.g., a project name): string name = "Alex";bool — True or false (e.g., is the permit approved?): bool approved = true;char — A single character (e.g., a grade): char grade = 'A';In the .NET world, local variables use camelCase — the first word is lowercase, and every subsequent word starts with an uppercase letter. Think of it as whispering the first word and then speaking normally.
firstName, totalCost, isReadyFirstName (PascalCase — reserved for methods/classes), first_name (snake_case — that's Python territory)1. Variables must be declared before use.
2. Variable names cannot start with a number or contain spaces.
3. C# is case-sensitive: age and Age are two different boxes.
4. Use var when the type is obvious from the right-hand side — it's not dynamic, C# still knows the exact type at compile time.