C# and .NET
C# (say "see sharp") is a modern programming language from Microsoft. It is type-safe: every value has a type, such as string or int, and the compiler stops code that mixes them up. C# programs run on .NET.
.NET is a free, open-source platform for Windows, macOS and Linux. Its dotnet tool makes projects: dotnet new console writes a project file and Program.cs. Later, dotnet run builds the program and runs it.
Here Program.cs holds three lines. There is no class and no Main method: these top-level statements simply run from top to bottom. var lets the compiler work out each type, so name and msg are strings.
Build: C# to IL
dotnet run builds first. The C# compiler, called Roslyn, reads every line and checks every type. A mistake such as msg * 2 (a string times a number) stops right here with an error, before anything runs.
Roslyn does not make machine code. It writes IL, intermediate language: small steps such as ldstr (load a string) and call. The IL goes into an assembly, the file Hello.dll, with metadata describing its types and methods.
Run: the CLR
Next, dotnet run starts the CLR, the common language runtime: the part of .NET that runs IL. It loads Hello.dll and starts at the top-level statements, which the compiler wrapped in a hidden Main method.
A CPU cannot run IL. The first time a method runs, the CLR's JIT (just-in-time) compiler turns its IL into machine code for this exact CPU, then keeps that code, so the next call starts at once.
The CPU runs the machine code. Line 1 stores "World" in name. Line 2 joins "Hello, " and name into a new string object, msg. New objects live on the heap: memory the CLR manages.
Line 3, Console.WriteLine(msg), hands the text to the operating system, which shows it in the console with a new line after it: Hello, World.
After line 3 nothing uses msg any more, so it is garbage. The garbage collector, part of the CLR, finds objects nothing can reach and frees their memory for reuse. You never free memory yourself.
The same Hello.dll runs on Windows, macOS or Linux, on x64 or Arm64 chips. IL is the same everywhere; each machine's CLR JIT-compiles it for its own CPU.
What happens
// step 1/11 · csharp
C# a programming language from Microsoft (first released 2002;
standard ECMA-334)
type-safe every value has a type: "World" is a string, 2 is an int
the compiler rejects code that mixes them up
runs on .NET
The IL card is shortened but in the real order. The full Debug listing also stores and loads the two locals (stloc, ldloc), has a few nop instructions, and names each method in full, such as System.String::Concat(string, string). Real .NET uses tiered compilation: a quick first compile, then a better one for methods that run often. Much of the .NET library ships already compiled (ReadyToRun), so the JIT mostly compiles your own methods.