TExcelTAD
Home › C# › C# Get Started

C# Get Started

To write C# on your own computer you need the .NET SDK, which contains the compiler, the runtime and the dotnet command-line tool. You can also skip installing anything for now — every playground on this site compiles and runs your code on a real .NET 9 compiler in the cloud.

Installing the .NET SDK

  1. Download the SDK for your operating system from the official .NET website (choose the latest LTS or current version).
  2. Run the installer (on Linux you can also use your package manager, e.g. sudo apt install dotnet-sdk-9.0).
  3. Open a new terminal and check the installation:
bash
dotnet --version
9.0.100

Your exact version number will differ — anything 8.0 or newer is fine for this tutorial.

Choosing an editor

Editor Notes
Visual Studio (Windows) Full IDE with designers, debugger and profiler
Visual Studio Code Lightweight, cross-platform; install the C# Dev Kit extension
JetBrains Rider Cross-platform commercial IDE with strong refactoring tools

Creating your first project

The dotnet tool creates, builds and runs projects. Create a console application in a new folder:

bash
dotnet new console -o HelloApp
cd HelloApp
dotnet run
Hello, World!

The template generates two important files:

File Purpose
HelloApp.csproj Project file: target framework, settings and package references
Program.cs Your source code

The generated Program.cs contains a single line that uses top-level statements:

csharp
// See https://aka.ms/new-console-template for more information
Console.WriteLine("Hello, World!");

Notice there is no using System; — the project template turns on implicit usings, which imports the most common namespaces automatically. In the playgrounds on this site we compile a single file without a project, so we always write the using lines ourselves.

Here is the same program as you would run it on this site. Edit the message, add a second line, and run it again — that is the whole edit-compile-run cycle:

csharp · try it yourself
using System;

Console.WriteLine("Hello, World!");
Console.WriteLine("My first .NET program is running.");
Hello, World!
My first .NET program is running.

Building versus running

C# is a compiled language. dotnet build turns your .cs files into an assembly (a .dll file containing intermediate language), and dotnet run builds if needed and then starts the program. At run time the .NET runtime's JIT compiler translates the intermediate language into machine code.

csharp · try it yourself
using System;

class Program
{
    static void Main()
    {
        Console.WriteLine("Compiled with C#");
        Console.WriteLine("Running on .NET " + Environment.Version.Major);
    }
}
Compiled with C#
Running on .NET 9

Environment.Version reports the version of the runtime that is executing your code — here, .NET 9.

Useful dotnet commands

Command What it does
dotnet new console Create a new console project
dotnet build Compile the project
dotnet run Build and run the project
dotnet add package <name> Add a NuGet package dependency
dotnet test Run unit tests
dotnet format Format the code according to style rules

Tip: NuGet is the package manager for .NET. Thousands of free libraries — for JSON, databases, testing and more — can be added with a single dotnet add package command.

Test yourself

Which command creates a new console application?

  1. dotnet create app
  2. dotnet new console
  3. csharp init
  4. dotnet start console

What does dotnet run do?

  1. Only formats code
  2. Only downloads packages
  3. Builds the project if needed and then runs it
  4. Publishes the app to the cloud