C# & .NET Framework Variables & Data Types
💡
Exercise 6

Declaring Variables — The Architect's Labeled Boxes 10 XP Easy

Ctrl+Enter Run Ctrl+S Save

🏗️ Welcome to the Workshop

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.

📦 The Five Essential Box Types

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';
// Explicit typing — you tell C# the exact box type string name = "Alex"; int age = 25; double height = 5.9; bool isArchitect = true; char initial = 'A'; // The 'var' keyword — C# figures out the box type for you var city = "Metropolis"; // inferred as string var population = 500000; // inferred as int

🏷️ Naming Conventions

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, isReady
  • FirstName (PascalCase — reserved for methods/classes), first_name (snake_case — that's Python territory)

💡 Key Rules

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.

📋 Instructions
### Your Mission The .NET Architect needs to set up their profile card. Declare the following variables and print them: 1. A `string` variable `name` with value `"Alex"` 2. An `int` variable `age` with value `25` 3. A `double` variable `height` with value `5.9` 4. A `bool` variable `isArchitect` with value `true` Print them in this exact format using `Console.WriteLine()`: ``` Name: Alex Age: 25 Height: 5.9 Is Architect: True ``` > **Tip:** In C#, `bool` values print as `True` / `False` (capitalized).
Declare each variable with its type (string, int, double, bool) and use Console.WriteLine($"Name: {name}") with string interpolation to print them.
main.py
Hi! I'm Rex 👋
Output
Ready. Press ▶ Run or Ctrl+Enter.