How to Install C# on Windows: Step-by-Step Guide
To install
C# on Windows, download and install the .NET SDK from the official Microsoft website. Then, install a code editor like Visual Studio Code to write and run your C# programs.Syntax
Installing C# on Windows involves setting up the .NET SDK which includes the C# compiler and runtime. You then use a code editor or IDE to write and run C# code.
Key parts:
.NET SDK: The software development kit that contains C# tools.Visual Studio Code: A lightweight editor to write C# code.dotnetcommand: Used in the terminal to create, build, and run C# projects.
bash
dotnet --version
Output
7.0.100
Example
This example shows how to create and run a simple C# console app after installing the .NET SDK.
bash
dotnet new console -o MyApp cd MyApp dotnet run
Output
Hello, World!
Common Pitfalls
Common mistakes when installing C# on Windows include:
- Not installing the
.NET SDKbut only the runtime, which lacks build tools. - Forgetting to add
dotnetto your system PATH, causing command not found errors. - Using an outdated version of the SDK that lacks new C# features.
- Not restarting the terminal after installation, so commands are not recognized.
bash
REM Wrong: Trying to run C# without SDK > dotnet new console 'dotnet' is not recognized as an internal or external command REM Right: After installing SDK and restarting terminal > dotnet new console Project created successfully.
Quick Reference
| Step | Command/Action | Description |
|---|---|---|
| 1 | Download .NET SDK | Get from https://dotnet.microsoft.com/download |
| 2 | Install Visual Studio Code | Optional but recommended editor |
| 3 | Verify installation | Run dotnet --version in terminal |
| 4 | Create new project | Run dotnet new console -o MyApp |
| 5 | Run project | Navigate to folder and run dotnet run |
Key Takeaways
Install the official .NET SDK to get C# compiler and tools on Windows.
Use Visual Studio Code or another editor to write and run C# code.
Verify installation with
dotnet --version in your terminal.Create and run projects using
dotnet new and dotnet run commands.Restart your terminal after installation to ensure commands work.