Skip to content
wannacode

Getting your computer ready

Problem

What you need

To write and run programs, you need two things:

  1. The .NET SDK (Software Development Kit): the compiler, the .NET runtime that runs programs, the standard libraries and the dotnet command.
  2. 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:
Terminal
sudo apt install dotnet-sdk-10.0

If 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:

Terminal
dotnet --version

You should see the version number. The numbers after 10.0 may be different:

10.0.402

The 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:

Terminal
dotnet new console -o Hello
cd Hello

The 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:

Program.cs
class Program
{
static void Main()
{
Console.WriteLine("Hello!");
}
}
Output
Hello!

Then run:

Terminal
dotnet run

dotnet 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 run command compiles into the bin folder, and the compiled program is Hello.dll. If you only want to compile without running, the command is dotnet build.
  • In C#, the file name does not have to match the class, but it is a good habit.
  • The short form without class Program and Main is called top-level statements. The compiler builds Main around 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. Type chcp 65001 and 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:

Output
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:

Program.cs
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
  1. The editor and the file on disk both have only the first line.
  2. You run dotnet run: the program is built from the file on disk.
  3. You add a second line in the editor. The file on disk is still the old one.
  4. You run it without saving: you still get only "Hello!".
  5. You save (Ctrl+S): the editor writes the text to the file on disk.
  6. 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 run from the wrong folder. Go into the folder with the .csproj file (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 --version shows whether .NET is installed.
  • dotnet new console -o Hello makes a project, and dotnet run compiles 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.

Made by Ivo Gergov as part of Evo Tech's campaign for accessible programming education ·