C# Program Structure, Top-Level Statements & .NET CLR Runtime
1Concept
C# 13 supports Top-Level Statements where the Roslyn compiler automatically generates the Program class and Main entry point. C# compiles to Common Intermediate Language (CIL/MSIL), stored in .dll assemblies, which the .NET Core CLR RyuJIT compiler converts into native machine code.
2Architecture Diagram
[Program.cs] ──► (Roslyn csc) ──► [App.dll (CIL)] ──► [.NET CLR (RyuJIT)] ──► Native Machine Code
3Code Example
Stage 0 Language Foundations
// Top-Level Statements in C# 13 / .NET 9
using System;
Console.WriteLine("=== .NET 9 / C# 13 Execution Pipeline ===");
Console.WriteLine($"CLR Version: {Environment.Version}");
Console.WriteLine($"OS: {Environment.OSVersion}");
Console.WriteLine($"Process Architecture: {Environment.ProcessArchitecture}");
Console.WriteLine($"Working Set Memory: {Environment.WorkingSet / (1024 * 1024)} MB");4Expected Output
=== .NET 9 / C# 13 Execution Pipeline === CLR Version: 9.0.0 OS: Microsoft Windows NT 10.0.22631.0 Process Architecture: X64 Working Set Memory: 28 MB
5Key Takeaways
- ✓Top-level statements remove static void Main boilerplate while generating the exact same IL.
- ✓The .NET CLR provides cross-platform execution with Tiered JIT compilation.
- ✓Global using directives allow sharing namespaces project-wide.