Loading lessons...
Getting Started with C#
Getting Started with C#
To write and run C# code you need the .NET SDK (Software Development Kit).
Install the .NET SDK
- Go to dotnet.microsoft.com/download.
- Download the latest SDK for your operating system.
- Run the installer and follow the steps.
Check if .NET is installed
Open a terminal (Command Prompt on Windows, Terminal on macOS/Linux) and type:
dotnet --version
If you see a version number, you're ready to go.
Create a new console project
Use the dotnet command-line tool to create a project:
dotnet new console -n HelloWorld
cd HelloWorld
This generates a Program.cs file plus a project file.
Run your program
dotnet run
If you're starting from scratch, Program.cs prints:
Console.WriteLine("Hello, World!");
Editors and IDEs
- Visual Studio - the full-featured IDE from Microsoft (Windows).
- Visual Studio Code - lightweight editor with the C# extension.
- JetBrains Rider - a popular third-party C# IDE.
The command-line compiler
You can also compile a single file with csc (the C# compiler), but the dotnet CLI is the recommended modern workflow.
TL;DR
- Install the .NET SDK from dotnet.microsoft.com.
dotnet new console -n Namecreates a project.dotnet runbuilds and runs it.- Visual Studio and VS Code are the most common editors.