C# & .NET Framework Hello, C#!
💡
Exercise 3

🏛️ Anatomy of a C# Program 15 XP Easy

Ctrl+Enter Run Ctrl+S Save

🏗️ Building a Skyscraper, Floor by Floor

Every great skyscraper has a defined structure — a foundation, floors, rooms, and a roof. A C# program is exactly the same! Let's dissect each "floor" of a C# program and understand what it does and why it's there.

Floor 0: The using Directives (The Supply Trucks)

Before construction begins, supply trucks arrive with materials. In C#, using directives import namespaces — collections of pre-built tools and classes.

using System; // Core tools: Console, Math, String, etc. using System.Collections; // Data structures: ArrayList, Hashtable using System.IO; // File operations: reading/writing files

Without using System;, you'd have to write System.Console.WriteLine() every single time. The using directive is like telling the delivery crew: "Just leave the System tools right here where I can reach them."

Floor 1: The namespace (The Building's Address)

A namespace is your building's address. It organizes your code and prevents naming conflicts. Imagine two architects both name their class "Calculator" — namespaces keep them separate!

namespace MyDigitalCity // Your unique address { // All your classes live inside here }

Real-world namespaces look like: Microsoft.AspNetCore.Mvc, Unity.Engine, MyCompany.ProjectName.Feature. They use dots to create a hierarchy, like a postal address: Country → City → Street.

Floor 2: The class (The Blueprint)

A class is the blueprint for a building. It defines what the building contains and what it can do. Every piece of C# code lives inside a class.

class Program // The blueprint { // Methods (actions), fields (data), properties (attributes) }

The name Program is just a convention for the main class. You could call it Skyscraper or CityBuilder — C# doesn't care about the name, only that it contains the Main method.

Floor 3: The Main Method (The Front Door)

The Main method is the front door of your program. When someone runs your application, the CLR (Common Language Runtime) looks for this exact method to start execution.

static void Main(string[] args) { // Execution starts HERE // This is where the magic happens! }

Let's decode each keyword:

  • static — This method belongs to the class itself, not to an instance. The runtime can call it without creating an object first.
  • void — This method doesn't return any value. (You can also use int to return an exit code, or async Task for async programs.)
  • Main — The special name the CLR looks for. Must be capital M!
  • string[] args — An optional array of command-line arguments. When you run myapp.exe hello world, args contains ["hello", "world"]. You can omit this parameter if you don't need it.

🏗️ The Complete Structure

Here's how all the floors stack together into one beautiful skyscraper:

using System; // Floor 0: Supply trucks namespace MyDigitalCity // Floor 1: Building address { class Program // Floor 2: The blueprint { static void Main() // Floor 3: The front door { Console.WriteLine("Construction complete!"); } } }

💡 Pro tip: In modern C# (version 9+), you can use top-level statements — writing code without the class and Main boilerplate. But as an architect, you should know the full structure first before taking shortcuts!

📋 Instructions
**Build a complete C# skyscraper!** Complete the program by: 1. Add the correct `namespace` declaration: `ArchitectAcademy` 2. Inside `Main()`, print exactly these three lines: ``` My name is Architect I am learning C# This is exercise 3 ``` Your program must have the full structure: - `using` directive - `namespace` - `class` - `Main` method with the three print statements
Replace the comment with: namespace ArchitectAcademy Then inside Main(), add three Console.WriteLine() calls: Console.WriteLine("My name is Architect"); Console.WriteLine("I am learning C#"); Console.WriteLine("This is exercise 3");
main.py
Hi! I'm Rex 👋
Output
Ready. Press ▶ Run or Ctrl+Enter.