In the last chapter I showed you one line of C# and told you it was a complete program. Today you’ll run it on your own computer. You need two things for that: .NET, which turns your code into something the computer can execute, and Visual Studio Code, the editor where you’ll write it.
By the end of this chapter you’ll have both installed, a project you created yourself and a program that prints your name. You’ll also see your first compiler error, on purpose.
What we’re installing
.NET comes in two flavors: the runtime, which only runs programs that already exist, and the SDK, which is what you use to build them. You’re going to write programs, so you need the SDK. The SDK already includes the runtime, so there’s nothing else to install.
Pick .NET 10, even if the page offers something else
When you open the download page you’ll see it recommends .NET 11, because it’s the newest. Pick .NET 10. It’s the long-term support (LTS) release, and it’s the one this path uses. For everything we’re going to learn, it works the same.
The exact version has more numbers after it, something like 10.0 followed by another number. That last part changes with every update and doesn’t matter for what we’re doing. What matters is that it starts with 10.
Install .NET 10 on Windows
You have two options. Use whichever feels more comfortable.
With the installer. Go to the .NET 10 download page. Find the SDK section, and in the Installers column look for the Windows row. Pick the link for your processor; if you’re not sure which one you have, the official docs recommend x64 because it’s the most common. Open the file you downloaded, click Install and follow the steps. If Windows asks for administrator permission, allow it.
With winget. If you’d rather use the terminal, open one (search for “Terminal” or “PowerShell” in the Start menu) and type:
winget install Microsoft.DotNet.SDK.10
Notice the 10 at the end. That number is what makes sure you get .NET 10 and not the newest release.
The official Windows install guide has every detail if something doesn’t look right.
Install .NET 10 on macOS
First, find out which kind of Mac you have. Click the Apple menu in the top-left corner and choose About This Mac. If the chip line says Apple M1, M2, M3 or any other M, you have Apple Silicon. If it says Intel, you have an Intel processor.
Now go to the .NET 10 download page. In the SDK section, Installers column, find the macOS row:
- Apple Silicon (M1 and later): pick Arm64.
- Intel: pick x64.
Get this one right. If you have Apple Silicon and download x64, .NET installs into a different folder and it isn’t the version you want.
Open the installer package you downloaded and follow the steps. The installer sets up your system so the terminal can find the dotnet command. The official macOS install guide has more detail.
If you’re on Linux, follow the official Linux install guide and choose .NET 10.
Check that it worked
Open a new terminal. On Windows, Terminal or PowerShell. On macOS, the Terminal app, which lives in Applications, inside Utilities. Type:
dotnet --version
You should see a number that starts with 10., for example:
10.0.300
Yours will probably be newer, and that’s fine. If the terminal says it doesn’t recognize dotnet, close the terminal, open it again and run the command once more.
The first time you use dotnet, the SDK may print a welcome message before the result. That’s normal, and it only shows up once.
Install Visual Studio Code and C# Dev Kit
Download VS Code from code.visualstudio.com/download. On Windows, the User Installer is enough. On macOS, pick the build for your chip (Apple silicon or Intel) or the Universal one, which works on both. Install it like any other app.
On its own, VS Code is a very good text editor, but it knows nothing about C#. That’s what the C# Dev Kit extension, published by Microsoft, is for. Go to its Marketplace page and click Install. That opens VS Code and asks whether you want to install the extension; say yes. C# Dev Kit automatically installs the C# extension too, which is the one that teaches VS Code to understand your code.
A note on the license. C# Dev Kit is free for personal use and for learning. If it asks you to sign in with a Microsoft account, you can do that. If you’d rather not, uninstall C# Dev Kit and keep only the “C#” extension. That one is enough for this whole part of the path.
Your first program
We’ll create the project from the terminal, so you see exactly what happens without buttons in the way. Go to the folder where you want to keep your projects and type:
dotnet new console -n HelloWorld
dotnet new console tells .NET to create a new console project, meaning a program that runs in the terminal. -n HelloWorld gives it a name. You’ll see something like this:
The template "Console App" was created successfully.
Processing post-creation actions...
Restoring .../HelloWorld/HelloWorld.csproj:
Determining projects to restore...
Restored .../HelloWorld/HelloWorld.csproj (in 21 ms).
Restore succeeded.
That created a HelloWorld folder with two files you care about:
HelloWorld.csproj: the project settings. Among other things, it says the project uses .NET 10 (net10.0). You don’t need to touch it for now.Program.cs: your code. The.csextension means C#.
There’s also an obj folder that .NET uses for its own internal work. Ignore it.
Open the folder in VS Code with File > Open Folder and choose HelloWorld. Open Program.cs. It has a single line:
Console.WriteLine("Hello, World!");
Now go back to the terminal, move into the project folder and run it:
cd HelloWorld
dotnet run
Hello, World!
That’s your first program running on your own machine.
What that line does
Console is the terminal. WriteLine means “write a line”. Whatever goes inside the parentheses is what you want to write, and the quotes mark where the text starts and ends. The semicolon at the end tells C# the instruction is finished.
Read it all together: “in the console, write this line: Hello, World!”.
Make it yours
Change Program.cs so it looks like this. Type it by hand, don’t paste it:
string name = "Lesther";
Console.WriteLine("Hello there");
Console.WriteLine($"Welcome, {name}");
Replace Lesther with your own name. Save the file (VS Code doesn’t save on its own) and run it again:
dotnet run
Hello there
Welcome, Lesther
The first line stores some text under the name name so you can use it later. The third line puts a $ before the quotes, which lets C# replace {name} with whatever you stored. Both ideas have proper names, variables and string interpolation, and we’ll go through them slowly in the next chapter. For now it’s enough to see that it works.
Your first error, on purpose
Delete the semicolon at the end of the second line, so it reads Console.WriteLine("Hello there"). Save and run dotnet run. You’ll see something like this:
.../HelloWorld/Program.cs(2,33): error CS1002: ; expected [.../HelloWorld/HelloWorld.csproj]
The build failed. Fix the build errors and run again.
It looks like a lot, but you read it in pieces:
Program.cs: the file with the problem. Before it comes the full path on your computer, which will be different from mine.(2,33): line 2, column 33. That’s right after the closing parenthesis, where the semicolon was missing.error CS1002: the error code. Every kind of error has its own, and it’s useful for looking it up.; expected: the message. The compiler expected a;and didn’t find one.
The last line tells you the program couldn’t be compiled, so it never ran. Put the semicolon back, save, run again and everything works.
You’re going to see a lot of errors like this one, and it doesn’t mean you’re doing it wrong. The compiler is telling you exactly where to look. Reading the message calmly, starting with the file and the line, solves most of them. Chapter 7 covers errors and debugging in depth.
What you have now
- .NET 10 installed, and
dotnet --versionstarts with10. - VS Code with C# Dev Kit, or with just the C# extension.
- A
HelloWorldproject created withdotnet new console. - A program that runs with
dotnet runand prints your name. - Your first compiler error, read and fixed.
That’s everything you need for the rest of Part 1.
Stuck on the install?
If something didn’t work, send me a DM on Instagram or ask in the Discord community. Tell me which system you’re on and what message you got, and we’ll sort it out.
