0
0
CsharpHow-ToBeginner · 4 min read

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.
  • dotnet command: 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 SDK but only the runtime, which lacks build tools.
  • Forgetting to add dotnet to 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

StepCommand/ActionDescription
1Download .NET SDKGet from https://dotnet.microsoft.com/download
2Install Visual Studio CodeOptional but recommended editor
3Verify installationRun dotnet --version in terminal
4Create new projectRun dotnet new console -o MyApp
5Run projectNavigate 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.