C# ยท Chapter 2 of 46

C# Install .NET SDK

To write and run C# programs, you need the .NET SDK (Software Development Kit), which includes the compiler, runtime, and command-line tools. It is free and available for Windows, macOS, and Linux.

Once installed, you can use the `dotnet` command-line tool to create, build, and run C# projects from any terminal, or use an IDE like Visual Studio or Visual Studio Code for a richer editing experience.

Syntax
dotnet new console -o MyApp
cd MyApp
dotnet run

Installing the .NET SDK

Download the .NET SDK installer from dotnet.microsoft.com for your operating system. After installing, run `dotnet --version` in a terminal to confirm it works.

Editors and IDEs

Visual Studio (Windows) is a full-featured IDE for C#. Visual Studio Code with the C# extension is a lightweight, cross-platform alternative. JetBrains Rider is another popular choice.

Example 1 (bash)
dotnet --version
Output
8.0.100

Checks that the .NET SDK is installed and shows its version.

Example 2 (bash)
dotnet new console -o HelloApp
cd HelloApp
dotnet run
Output
Hello, World!

Creates a new console project, then builds and runs it.

Key points

  • The .NET SDK includes the compiler, runtime and CLI tools.
  • The `dotnet` command is used to create, build, and run projects.
  • Visual Studio, VS Code, and Rider all support C# development.
  • .NET is free, open-source, and cross-platform.
๐Ÿ’ก Note: Always install the latest LTS (Long Term Support) version of .NET for stability.

๐Ÿ“ Quick Quiz

1. Which command checks your installed .NET version?

2. Which command creates a new console project?

3. Which of these is a C# IDE?