Before you write your first program, you set up your workshop. There are two ways to do it, and you only need one of them:

  • Option A: on your own computer. You install the .NET SDK and an editor. This is the usual way, and once everything is installed, it works without an internet connection too.
  • Option B: in your browser with GitHub Codespaces. You install nothing. A computer in the cloud gives you an editor and a terminal in your browser. You need a free GitHub account. This option fits if you aren’t allowed to or can’t install anything on your device, such as a work laptop or a Chromebook.

Read the section on the terminal first. Then follow the section for your system or for Codespaces, and finish with the test run.

What you install

The .NET SDK (SDK stands for Software Development Kit) contains everything you need to program in C#: the compiler, the dotnet tool, and the ready-made building blocks. It’s free and open source. This course needs .NET 10 or later, because only since version 10 can you start a program from a single file. .NET 10 is a long-term support release: Microsoft keeps it updated for three years.

Here are Microsoft’s official instructions, in case something looks different on your computer:

The terminal

A terminal is a window where you give the computer commands as text instead of clicking with the mouse. You type a command, press Enter, and the computer answers with text. For this course you only need a handful of commands.

How to open it:

  • Windows: Open the Start menu, type “Terminal,” and press Enter. Windows Terminal opens with PowerShell. On older systems the entry is called “Windows PowerShell”; that works just the same.
  • macOS: Press Command+Space to open Spotlight search, type “Terminal,” and press Enter.
  • Linux: On Ubuntu press Ctrl+Alt+T; otherwise use the applications menu (“Terminal”).
  • Codespaces: The terminal is the panel at the bottom of the editor.

These commands work the same way on Windows (PowerShell), macOS, and Linux:

Command What it does
pwd Shows which folder you’re in right now.
ls Lists what’s in the current folder.
mkdir csharp-k0 Creates a folder named csharp-k0.
cd csharp-k0 Changes into that folder.
cd .. Goes up one folder.

The Up Arrow key brings back your last command. The Tab key completes file and folder names as soon as the first few letters are unique. Both save you a lot of typing.

Option A on Windows

You have two choices. Both need administrator rights on the computer.

With the installer:

  1. Open the page Download .NET 10.0.
  2. In the SDK box, in the Windows row, choose x64. Only on devices with an Arm processor (for example, with a Snapdragon chip) do you choose Arm64.
  3. Run the downloaded file and follow the installer.

Or with one command in the terminal (using the WinGet package manager, which comes with current versions of Windows):

PowerShell
winget install Microsoft.DotNet.SDK.10

Then close all terminal windows and open a new one. Only a new window knows the dotnet command.

Option A on macOS

  1. Find out which processor your Mac has: Apple menu, “About This Mac.” If it shows Chip with “Apple M…,” you have an Apple processor. If it shows Processor with “Intel,” you have an Intel processor.
  2. Open the page Download .NET 10.0.
  3. In the SDK box, in the macOS row, choose Arm64 for an Apple chip, x64 for Intel.
  4. Open the downloaded .pkg file and follow the installer.

Then open a new terminal window.

Option A on Linux

On Ubuntu 24.04 and later, the SDK is in Ubuntu’s own package feeds:

Bash
sudo apt-get update
sudo apt-get install -y dotnet-sdk-10.0

For Ubuntu 22.04, Debian, Fedora, and other distributions, Microsoft’s Linux instructions describe the right way.

Option A: an editor

Programs are text files. In principle any editor that saves plain text will do. It’s more pleasant to use an editor that knows C#, shows your code in color, and marks typos. We recommend Visual Studio Code, free for Windows, macOS, and Linux:

  1. Install Visual Studio Code.
  2. On the left, open the Extensions view (the icon with four squares), search for C#, and install the “C#” extension from Microsoft. That’s all this course needs.

Visual Studio Code may also offer you the C# Dev Kit. You don’t need it for this course. It’s free for individuals; in companies the same license terms as for Visual Studio apply.

If you’d rather use a simple editor: on Windows, Notepad works, but when you save, set “Save as type” to “All files,” or it adds .txt to the name. On macOS, TextEdit saves plain text only if you first choose “Make Plain Text” from the “Format” menu.

Option B: GitHub Codespaces

  1. Create a free account on github.com if you don’t have one yet.
  2. Open github.com/dotnet/tutorial-codespace. Microsoft provides this template for its own C# tutorials; the .NET 10 SDK is already installed in it.
  3. Click the green Code button, choose the Codespaces tab, and click +.
  4. After a minute or two, Visual Studio Code opens in your browser with a terminal at the bottom.

This template also has GitHub Copilot set up, an AI that suggests whole lines as you type. For this course, it’s better to ignore the suggestions or turn them off: you learn the most when you write every line yourself.

About the cost: a free GitHub account includes 120 hours of compute time every month, counted per processor core (GitHub calls them core hours). This template runs on a machine with four cores, so you have about 30 hours a month, more than this course needs. If you haven’t added a payment method, GitHub stops the codespace when the allowance is used up instead of charging you. The exact terms are in GitHub’s documentation.

A codespace stops by itself after a while without input, and you can open it again at github.com/codespaces. Your files are stored in the codespace, not on your device. If you want to keep a file, right-click it in the editor’s file list on the left and choose “Download.” GitHub deletes a codespace you haven’t used for 30 days on its own, along with the files in it. When you’ve finished the course, you can also delete it there yourself.

Exercise 1

Check your installation and create your course folder:

  1. Open a new terminal.
  2. Type dotnet --version. The answer must start with 10. (or a higher number).
  3. Create a folder csharp-k0 with mkdir and change into it with cd.
  4. Use pwd to show where you are now.

For this course, always work in this folder of your own. If a folder already contains project files (files ending in .csproj), dotnet run starts that project instead of your file.

Solution 1

On Windows it looks something like this (the lines with PS are what you type; your version number and your user name will be different):

PS C:\Users\Ada> dotnet --version
10.0.100
PS C:\Users\Ada> mkdir csharp-k0
PS C:\Users\Ada> cd csharp-k0
PS C:\Users\Ada\csharp-k0> pwd

Path
----
C:\Users\Ada\csharp-k0

On Windows, mkdir also prints a small table with the new folder; it’s left out here. On macOS, on Linux, and in Codespaces it looks similar, just with different paths:

$ dotnet --version
10.0.100
$ mkdir csharp-k0
$ cd csharp-k0
$ pwd
/home/ada/csharp-k0

If the terminal says the command dotnet isn’t recognized when you type dotnet --version, close all terminal windows and open a new one. If that doesn’t help, restart your computer. If dotnet --version shows a number that starts with 8 or 9, an older version is installed: install .NET 10 as well. Several versions get along fine side by side.

Exercise 2

Practice moving between folders. In csharp-k0, create a folder practice, change into it, go back with cd .., and delete the empty folder practice again. You don’t know the command for deleting yet: it’s called rmdir and works like mkdir.

Solution 2

Bash
mkdir practice
cd practice
pwd
cd ..
rmdir practice
ls

After cd practice, pwd shows a path that ends in practice; after cd .. you’re back in csharp-k0. rmdir deletes only empty folders, so you can’t lose anything important with it. At the end, ls shows that practice is gone.

Test run

Finally, you check that the compiler and the tool work together. In the csharp-k0 folder, use your editor to create a file test-run.cs (in Visual Studio Code: the “File” menu, “Open Folder…,” choose the csharp-k0 folder, then the New File icon on the left). Type exactly these lines into it and save:

C#
// test-run.cs
Console.WriteLine($"All set. .NET {Environment.Version} is running.");

Start it in the terminal, in the csharp-k0 folder:

Bash
dotnet run test-run.cs

The first start can take a few seconds, because the compiler translates the file for the first time. Then you see a line like this one (your version number is probably different; it just has to start with 10 or higher):

All set. .NET 10.0.11 is running.

You’ll learn exactly what the line means in the next lesson. When you see it, your workshop is ready.

What you can do now

  • You’ve installed the .NET 10 SDK or started a codespace, and dotnet --version answers with 10 or higher.
  • You can open a terminal and use pwd, ls, mkdir, cd, and rmdir in it.
  • You have an editor that saves plain text and a folder of your own for the course.
  • Your first program, test-run.cs, has run.

Read more