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

⚙️ The .NET Ecosystem 15 XP Medium

Ctrl+Enter Run Ctrl+S Save

🌆 The City Behind the Architect

You've been writing C# code — but what actually runs it? Behind every great architect is an entire city infrastructure: power grids, water systems, roads, and workers. In the C# world, that infrastructure is called .NET (pronounced "dot net").

Let's explore the city's infrastructure and understand how your blueprints become real buildings!

📊 The Evolution of .NET

The .NET platform has evolved significantly over the years. Understanding this history will help you navigate the ecosystem like a pro:

  • .NET Framework (2002–2019) — The original. Windows-only, powerful, and mature. Think of it as the first city ever built — huge and grand, but you can only live there if you're on Windows. Latest version: 4.8.1.
  • .NET Core (2016–2019) — The revolution! Cross-platform (Windows, macOS, Linux), open-source, and lightweight. Like building a portable city that runs anywhere. Versions 1.0 → 3.1.
  • .NET 5+ (2020–now) — The unification! Microsoft merged .NET Framework and .NET Core into a single platform. No more confusion! .NET 5 → 6 → 7 → 8 → 9. Each version is faster, leaner, and more powerful.
  • .NET 8 (LTS) — The current Long-Term Support release. Production-ready, blazing fast, and the recommended choice for new projects in 2024–2025.

🏭 The CLR — The Master Foreman

The Common Language Runtime (CLR) is like a master foreman who translates your blueprints into actual construction. When you write C# code, you're drawing blueprints. The CLR reads those blueprints and builds the actual structures in memory.

The CLR handles:

  • Memory Management — The Garbage Collector (GC) automatically cleans up unused objects, like a cleanup crew that demolishes abandoned buildings.
  • Type Safety — Ensures you don't accidentally put a string where an integer should go. Like a building inspector checking every brick.
  • Exception Handling — Catches errors gracefully instead of crashing. Like fire sprinklers activating when something goes wrong.
  • Thread Management — Handles parallel execution. Like coordinating multiple construction crews working on different floors simultaneously.
  • Security — Code Access Security and verification ensure your code doesn't do anything malicious.

📚 The BCL — The Standard Toolbox

The Base Class Library (BCL) is your standard toolbox. It contains thousands of pre-built classes organized into namespaces:

  • System — Core types: String, Int32, Console, Math, DateTime
  • System.Collections.Generic — Data structures: List, Dictionary, Queue, Stack
  • System.IO — File and stream operations
  • System.Linq — Powerful data querying (one of C#'s superpowers!)
  • System.Net.Http — HTTP client for web requests
  • System.Threading.Tasks — Async/await and parallel programming

🔨 The Compilation Pipeline

Ever wonder what happens when you hit "Run"? Your code goes through an amazing transformation — like turning a paper blueprint into a real building:

// Step 1: You write C# source code Console.WriteLine("Hello!"); // Step 2: The Roslyn compiler converts it to IL (Intermediate Language) // IL is like a universal blueprint that any worker can read // Step 3: At runtime, the JIT (Just-In-Time) compiler converts // IL into native machine code for YOUR specific CPU // The pipeline: // C# Source Code → [Roslyn Compiler] → IL Code (.dll/.exe) // → [JIT Compiler at Runtime] → Native Machine Code

Why this two-step process? Because IL is platform-independent! You compile once, and the JIT compiler optimizes it for whatever machine runs it — Windows, Linux, macOS, ARM, x86. It's like writing blueprints in a universal language that any construction crew in any country can read and build from.

🆚 JIT vs AOT Compilation

  • JIT (Just-In-Time) — Compiles IL to machine code at runtime, method by method. Allows runtime optimizations but has a "warm-up" cost. This is the default.
  • AOT (Ahead-Of-Time) — Compiles directly to native code before execution. Faster startup, no warm-up, but less runtime optimization. Used in .NET Native and NativeAOT (.NET 7+).

🔍 Inspecting the Runtime

C# lets you peek under the hood and see what version of .NET is powering your program. The Environment class provides this information:

// Get the CLR version Console.WriteLine(Environment.Version); // Get the framework description Console.WriteLine(System.Runtime.InteropServices.RuntimeInformation.FrameworkDescription);
📋 Instructions
**Explore the .NET engine room!** Write a program that prints exactly these three lines: ``` CLR Version: [version] .NET is amazing! C# compiles to IL, then JIT compiles to machine code ``` For the first line, use `Environment.Version` to get the actual CLR version: ```csharp Console.WriteLine("CLR Version: " + Environment.Version); ``` Then print the other two lines using regular `Console.WriteLine()` calls. **Note:** The CLR version output will vary depending on your runtime, and that's okay!
Use string concatenation with + to combine text and the version: Console.WriteLine("CLR Version: " + Environment.Version); Console.WriteLine(".NET is amazing!"); Console.WriteLine("C# compiles to IL, then JIT compiles to machine code");
main.py
Hi! I'm Rex 👋
Output
Ready. Press ▶ Run or Ctrl+Enter.