Getting your computer ready
Problem
What you need
To write and run programs, you need two things:
- The .NET SDK (Software Development Kit): the compiler, the .NET runtime that runs programs, the standard libraries and the
dotnetcommand. - An editor for your code. You could write a program in Notepad, but an editor for programmers colors the code, gives you hints and shows errors as you type.
If you do not have a computer you can install programs on yet, an online editor is enough for the first few days: search the web for online C# compiler. The tasks from the "Language basics" module work there too. For the bigger programs later on, you will need an installation.
The idea
Install the .NET 10 SDK
We use .NET 10. This is a long-term support version (LTS): it gets fixes until November 2028. Download it from dotnet.microsoft.com, in the Download section.
- Choose the SDK, not the Runtime. The Runtime only runs finished programs, while the SDK can also build them.
- Windows and macOS: download the installer for the .NET 10.0 SDK and run it.
- Linux: on Ubuntu, the package comes with the system:
sudo apt install dotnet-sdk-10.0If you have an older version (.NET 8, for example), install .NET 10 next to it: several versions live side by side without any trouble.
Check. Open a new terminal (on Windows: PowerShell or Command Prompt) and type:
dotnet --versionYou should see the version number. The numbers after 10.0 may be different:
10.0.402The idea
Choose an editor
Three good options:
- Visual Studio Community (Windows only): free for learning and personal projects. During installation, choose the .NET desktop development workload. You run the program with the green triangle at the top or with F5.
- Rider from JetBrains: runs on Windows, macOS and Linux and is free for non-commercial use, which includes learning.
- Visual Studio Code with the C# Dev Kit extension from Microsoft: a light editor for every system.
Which editor you choose does not matter much. What matters more is that you get used to one and use it every day.
See it
Your first program on your computer
In the terminal, go to the folder for the course and create a new project:
dotnet new console -o Hellocd HelloThe command makes a folder named Hello with two files: Hello.csproj (the project description) and Program.cs (the code).
The template puts a single line in Program.cs, Console.WriteLine("Hello, World!");, without class and Main. This is a short form that C# allows. In the course we write the full form, because it shows where the program starts. Replace the content of Program.cs with this:
class Program{ static void Main() { Console.WriteLine("Hello!"); }}Hello!Then run:
dotnet rundotnet run compiles the project and runs it. You run it from the folder that holds Hello.csproj.
More precisely, if you are curious
- The
dotnet runcommand compiles into thebinfolder, and the compiled program isHello.dll. If you only want to compile without running, the command isdotnet build. - In C#, the file name does not have to match the class, but it is a good habit.
- The short form without
class ProgramandMainis called top-level statements. The compiler buildsMainaround those lines on its own. You will see it in examples online.
- If the Windows terminal shows question marks or odd symbols instead of characters such as
€oré, the terminal is not set up for UTF-8. Typechcp 65001and run the program again. Editors usually do not have this problem.
Try it
Change it and run it again
Add a second line that prints "Your computer is ready.", save the file and run the program again. You should see:
Hello!Your computer is ready.If you see only "Hello!", the file most likely is not saved. Here is the whole program, in case you get stuck:
class Program{ static void Main() { Console.WriteLine("Hello!"); Console.WriteLine("Your computer is ready."); }}Why a change you have not saved does not reach the program:
class Program{ static void Main() { Console.WriteLine("Hello!"); Console.WriteLine("Your computer is ready."); }}Step by step, in words
- The editor and the file on disk both have only the first line.
- You run dotnet run: the program is built from the file on disk.
- You add a second line in the editor. The file on disk is still the old one.
- You run it without saving: you still get only "Hello!".
- You save (Ctrl+S): the editor writes the text to the file on disk.
- You run it again: now the program sees the second line too.
The idea
When it will not start
- "'dotnet' is not recognized…" (Windows) or "command not found" (macOS, Linux): the terminal cannot find .NET. Close it and open a new one, because the old one does not see the changes from the installation.
- "Couldn't find a project to run": you are running
dotnet runfrom the wrong folder. Go into the folder with the.csprojfile (cd Hello). - "No .NET SDKs were found": only the Runtime is installed. Install the SDK.
- "error CS…" with a line number: the program has reached the compiler, so the installation is fine. Compare your code with the example character by character.
In short
In short
- You need the .NET 10 SDK and an editor: Visual Studio Community, Rider or VS Code with the C# Dev Kit.
dotnet --versionshows whether .NET is installed.dotnet new console -o Hellomakes a project, anddotnet runcompiles and runs it.
- If the terminal cannot find the command, open a new terminal.
Next comes the lesson on how to solve a task before a single line of code is written.