$ dotnet new console -o Hello$ cd Hello$ dotnet runHello, World!Your name? AdaHi, Ada!$ .NET runtimename1// My first C# program2Console.WriteLine("Hello, World!");3Console.Write("Your name? ");4var name = Console.ReadLine();5Console.WriteLine($"Hi, {name}!");C# compilerHello.dllHello.csprojHello, World!Your name?AdaAdaHi, Ada!
Front row: your files and the build (Program.cs → compiler → Hello.dll)Back row: the run (terminal, .NET runtime, the variable name)Moving: the code, the built file, each line's text, your input and the value of nameFront row: your code in Program.cs, the C# compiler, the built file Hello.dll and the project file Hello.csproj. Back row: the terminal, the .NET runtime and the variable name, a box in memory. dotnet run builds the code, then runs it line by line: each line lights up as it runs, its text reaches the terminal, and the cursor shows where the next text goes. You type Ada; it is kept in name and used in the greeting Hi, Ada!. The letters you type are shown by the terminal, not by the program (the terminal echoes them). If the input came from a file instead, the program's own output would be Hello, World!, then Your name? Hi, Ada! on one line.

Write it

  1. Open a terminal and type dotnet new console -o Hello. It makes a folder called Hello with two files: Hello.csproj, the project file with its settings, and Program.cs, where your code goes. Then cd Hello moves into that folder.

Build and run

Line by line

What happens

// step 1/11 · new-project
$ dotnet new console -o Hello
  Hello/
    Hello.csproj   the project file: settings, target framework
    Program.cs     your code
$ cd Hello       go into the folder

The letters you type are shown by the terminal, not by the program (the terminal echoes them). If the input came from a file instead, the program's own output would be Hello, World!, then Your name? Hi, Ada! on one line. WriteLine ends the line with Environment.NewLine: a line feed (\n) on macOS and Linux, a carriage return and line feed (\r\n) on Windows.