Set Up Your Language · 6 of 14
Setting Up C#
C# (said "C sharp") is Microsoft's main programming language. It is used for Windows programs, business websites and services, and games built with the Unity game engine. You need the free .NET SDK (Software Development Kit) from Microsoft.
New to all this? Read Before you start on the main page first: it shows how to open Terminal, make a folder for your code, and see file name endings. It takes five minutes and prevents most problems.
1 What to download, and from where
Download only from dotnet.microsoft.com, Microsoft's official .NET website. Other download sites can bundle unwanted software.
- Go to dotnet.microsoft.com/download.
- Choose the version marked LTS (Long-Term Support), version 10 or newer.
- Click Download .NET SDK x64. Make sure it says SDK: the "Runtime" downloads can only run programs, not build them.
2 Install it on Windows
- Open the downloaded file (named like
dotnet-sdk-10.x.xxx-win-x64.exe). - Click Install, then Yes if Windows asks. It takes a minute or two.
- When it says Installation was successful, click Close.
3 Check that it worked
Close every Terminal window you have open and open a new one. A Terminal that was already open does not know about programs installed after it started. Then type this and press Enter:
dotnet --versionWhat you will see: A version number, 10 or higher. The first time you run dotnet it may also print a welcome message; that is normal.
10.0.100
If you see an error such as "is not recognized" instead, look at the common mistakes at the bottom of this page.
4 Write and save your first program
A program is just a text file. You can write it in Notepad, which comes with Windows. (Later you may like the free Visual Studio Code editor from code.visualstudio.com, which colours the code and helps spot mistakes.)
- Open Notepad (press the Windows key, type Notepad, press Enter).
- Type the program below, or click Copy and paste it in with Ctrl + V. Every symbol matters, so copy it exactly.
Console.WriteLine("Hello, World!"); - In Notepad choose File → Save as. Go to your
C:\codefolder. Set Save as type to All files (*.*), type the file namehello.csexactly as shown, including the dot and the ending, and click Save.
Console.WriteLine writes a line of text on the screen. The semicolon at the end marks the end of the instruction, like a full stop.
Do not use Word. Word saves extra formatting and changes straight quotes " into curly ones “ ”, which no programming language accepts.
5 Run it and see the result
Open File Explorer, go into your C:\code folder, right-click an empty part of the window and choose Open in Terminal. (More ways to open Terminal.) If Terminal was already open from the check above and is in another folder, type cd C:\code and press Enter.
Type this and press Enter:
dotnet run hello.csWhat you will see: the words below on a new line. That is your program running.
Hello, World!
The first run takes a few seconds because .NET builds the program first; the next runs are faster. Running a single .cs file like this needs .NET 10 or newer. With older versions, make a project instead: dotnet new console -o hello, then cd hello and dotnet run.
Congratulations: you have written and run a C# program.
6 Common beginner mistakes and how to fix them
Error messages look alarming but are usually precise: read the first line, and look for a line number. If you are stuck, copy the whole error message and paste it into an AI assistant along with your code, and ask what it means.
No .NET SDKs were found
Why: only the .NET Runtime is installed (some other programs install it), not the SDK.
Fix: go back to the download page and install the one labelled SDK.
error CS1002: ; expected
Why: the semicolon at the end of the line is missing.
Fix: add ; at the end. The numbers in brackets in the error, such as (1,36), tell you the line and the position on the line where it noticed the problem.
Couldn't find a project to run
Why: your .NET is older than version 10, which cannot run a single file.
Fix: install the latest LTS SDK, or use the project method in the note above.