Free Handbook · Every example compiled & verified

C# Handbook

Learn C# the way it is written at work. Seventeen modules from your first program to a job: every example program was compiled and run with the .NET 10 SDK before publishing, with its output shown exactly as it printed, and the real compiler errors and runtime exceptions you will hit are explained with the fix. Variables and types, flow control and pattern matching, strings and arrays, methods, classes, records and structs, inheritance and interfaces, exceptions, collections and generics, LINQ, async and await, debugging, C# with NuGet, ASP.NET Core, xUnit, EF Core, Redis, Blazor, Docker and GitHub Actions, data structures and algorithms, problem-solving patterns, interview questions, a certification exam, and a resume check at the end.

0 / 142 lessons🔥 0 day streak
ShareXLinkedIn

How this handbook works

Every lesson has a complete C# program with the exact output it prints — each one compiled and run with the real C# toolchain before it was published, so what you see is what you will get when you run it yourself — a trace of what the program did line by line where that matters, and the real compiler or runtime error you will hit next, with why it happened and the fix. Lessons tick themselves as you go. Finish the handbook, sit the exam, get the certificate, then take your resume through the ATS checker against a real job posting.

17modules
142lessons
137compiled examples
74real errors explained

Module 00 · what you'll be able to do

  • Install the .NET SDK on macOS, Windows or Linux and confirm it with dotnet --version
  • Run a single C# file with dotnet run app.cs and create a full project with dotnet new console
  • Choose between Visual Studio, VS Code and Rider for your own work
  • Explain what the C# compiler, IL, the CLR and the JIT each do when your program runs
  • Read the structure of a C# program: top-level statements, Main, using directives, namespaces and comments
01

Why learn C#

C# (said "C sharp") is a statically typed, object-oriented language that runs on .NET, Microsoft's free, open-source, cross-platform runtime. It was designed at Microsoft by Anders Hejlsberg and released in 2000; today it runs the same on Windows, macOS and Linux, and ships a new major version every November alongside .NET.

The reason to learn it is simple: one language covers an unusually wide range of real jobs. The same syntax you learn in Module 01 is what a backend developer writes in an ASP.NET Core API, what a game developer writes in Unity, and what an enterprise team writes for internal tools on Azure.

Where C# is usedWhat you buildFramework
Web backends and APIsREST and gRPC services, microservices, background workersASP.NET Core
GamesPC, console and mobile gamesUnity (C# scripting), Godot
CloudServerless functions, queue workers, cloud-native servicesAzure Functions, AWS Lambda .NET runtime
DesktopWindows and cross-platform desktop appsWPF, WinForms, .NET MAUI, Avalonia
Web front endsInteractive UIs written in C# instead of JavaScriptBlazor
EnterpriseBanking, insurance, healthcare and logistics systemsASP.NET Core, Entity Framework Core
In real jobs
Most C# job listings say ".NET developer" or "C#/.NET engineer" and ask for ASP.NET Core, Entity Framework Core, SQL Server or PostgreSQL, and a cloud (usually Azure). Everything in this handbook up to Module 10 is the language itself — the part every one of those roles assumes you already know cold.

C# is a good first language if you want

  • A compiler that catches type mistakes before the program runs
  • One language for backend, desktop, games and cloud
  • Excellent free tooling (Visual Studio, VS Code, Rider)
  • Stable, well-paid enterprise and game-studio jobs

Things to know going in

  • You compile before you run — a few seconds per change in a big project
  • The standard library is large; you learn it gradually
  • Lots of old tutorials target the Windows-only .NET Framework — prefer anything that says .NET 8 or later
02

Install the .NET SDK

To write C# you need the .NET SDK (Software Development Kit). It contains the C# compiler, the runtime, the standard library and the dotnet command-line tool you will use for everything: creating projects, building, running, testing and adding packages. The runtime alone (without "SDK") can only run finished apps — install the SDK.

bashmacOS
# with Homebrew
brew install --cask dotnet-sdk

# check it worked
dotnet --version
powershellWindows
# with winget (built into Windows 10 and 11)
winget install Microsoft.DotNet.SDK.10

# open a NEW terminal, then check
dotnet --version
bashLinux (Ubuntu / Debian)
sudo apt-get update
sudo apt-get install -y dotnet-sdk-10.0

dotnet --version

On other distributions, the official installers and the dotnet-install script are listed on the .NET download page (dot.net).

dotnet --version prints the SDK version, such as 10.0.100. If the terminal says "command not found", close it and open a new one so it picks up the updated PATH.

Which version?
Install the newest SDK. Even-numbered releases (.NET 8, .NET 10) are LTS — supported for three years — which is what most companies run. This handbook teaches C# 12 and later and every example was run on .NET 10. A newer SDK can still build projects that target older versions.
03

Your first program: dotnet run

Since .NET 10 you can run a single C# file directly — no project file needed. Create a file called app.cs, put one line in it, and run it:

C#app.cs
Console.WriteLine("Hello, World!");
Outputcompiled & run with real C#
Hello, World!
Your turn

Change the text to your own name and run dotnet run app.cs again. Then add a second Console.WriteLine line.

bash
dotnet run app.cs

The first run takes a few seconds because it compiles the file; later runs of an unchanged file are much faster because the build is cached.

Console.WriteLine prints text followed by a new line. Console is a class from the System namespace, WriteLine is a method on it, the text in double quotes is a string, and the ; ends the statement. Every statement in C# ends with a semicolon.

A real project: dotnet new console

Single-file apps are perfect for learning and scripts. Real applications live in a project — a folder with a .csproj file that lists the target framework and any NuGet packages. Create one with a template:

bash
dotnet new console -o HelloApp
cd HelloApp
dotnet run
xmlHelloApp/HelloApp.csproj
<Project Sdk="Microsoft.NET.Sdk">

  <PropertyGroup>
    <OutputType>Exe</OutputType>
    <TargetFramework>net10.0</TargetFramework>
    <ImplicitUsings>enable</ImplicitUsings>
    <Nullable>enable</Nullable>
  </PropertyGroup>

</Project>

The project file the template generates. Program.cs sits next to it; the build writes to bin/ and obj/ — never commit those two folders to git.

CommandWhat it does
dotnet run app.csCompile and run a single file (.NET 10+)
dotnet new console -o NameCreate a new console project in a folder
dotnet runBuild and run the project in the current folder
dotnet buildCompile only; shows every error and warning
dotnet add package NameAdd a NuGet package to the project
dotnet testRun the tests in a test project
dotnet project convert app.csTurn a single-file app into a full project when it outgrows one file
Error you will hit

CS1002: ; expected

C#
Console.WriteLine("Hello, World!")
Console.WriteLine("Welcome to C#");
Program.cs(1,35): error CS1002: ; expected

The build failed. Fix the build errors and run again.
Why the compiler said that

The first statement has no semicolon. C# does not treat a line break as the end of a statement, so the compiler reaches the end of line 1 still inside that statement. (1,35) is line 1, column 35 — exactly where it expected the ;.

The fix

Add the missing semicolon. Every C# error has this shape: file, (line,column), the code CSxxxx, and a message. Search the code to find the official docs page for it.

C#
Console.WriteLine("Hello, World!");
Console.WriteLine("Welcome to C#");
04

Visual Studio, VS Code or Rider

You can write C# in any text editor and run it with dotnet, but a proper IDE gives you IntelliSense (autocomplete that knows every type), red squiggles for compiler errors as you type, a debugger with breakpoints, and refactoring tools. There are three serious choices:

ToolRuns onCostBest for
Visual Studio (Community edition)WindowsFree for individuals, students and open sourceThe full Microsoft experience: designers for WPF/WinForms, profilers, the deepest debugger
VS Code + C# Dev Kit extensionWindows, macOS, LinuxFreeLightweight, great for single files and web APIs, the same editor many developers already use for everything else
JetBrains RiderWindows, macOS, LinuxFree for non-commercial use, paid for commercialStrong refactoring and code analysis; popular with Unity and on macOS
Just starting? Pick VS Code
Install VS Code, then the C# Dev Kit extension from the Extensions panel. Open the folder containing your app.cs or .csproj and you get IntelliSense, errors and a Run/Debug button. You can switch to Visual Studio or Rider later — your code does not change, only the editor around it.
05

How C# runs: compiler, IL, CLR and JIT

C# is not compiled straight to machine code, and it is not interpreted line by line either. It goes through two stages, and knowing them explains a lot of things you will see later — the .dll files in bin/, why the first call to a method is slightly slower, and why C# and F# code can call each other.

  1. 1
    1. The C# compiler (Roslyn) checks and compiles

    It reads your .cs files, checks every type, and reports errors like CS1002. If everything is valid it produces an assembly — a .dll file containing IL (Intermediate Language), a CPU-independent bytecode, plus metadata describing every type and method.

  2. 2
    2. The CLR loads the assembly

    The CLR (Common Language Runtime) is the engine that runs .NET code. It loads your assembly and the standard library, checks the IL is safe, and sets up the garbage-collected memory your objects will live in.

  3. 3
    3. The JIT turns IL into machine code

    The first time each method is called, the JIT (just-in-time) compiler translates its IL into native instructions for the actual CPU — x64 or ARM64. Later calls reuse that native code, and hot methods are recompiled with more optimisations as the program runs.

  4. 4
    4. The garbage collector cleans up

    You create objects with new but never free them yourself. The GC finds objects nothing refers to any more and reclaims their memory automatically.

.NET (what you should use)

  • Cross-platform: Windows, macOS, Linux
  • Open source, new version every year
  • Versions .NET 5, 6, 7, 8, 9, 10 …
  • Where all new development happens

.NET Framework (legacy)

  • Windows only
  • Frozen at version 4.8 — security fixes only
  • Still found in older enterprise codebases
  • Avoid for anything new
.NET SDK
The developer kit: compiler, runtime, standard library and the dotnet CLI.
CLR
Common Language Runtime — the engine that loads assemblies, JIT-compiles IL and manages memory.
IL
Intermediate Language — the CPU-independent bytecode the C# compiler produces.
JIT
Just-in-time compiler — turns a method's IL into native machine code the first time it runs.
Assembly
A compiled .dll or .exe containing IL and metadata.
BCL
Base Class Library — the standard library: Console, string, List<T>, files, networking and more.
NuGet
The package manager for .NET; dotnet add package installs from nuget.org.
Garbage collector
The part of the CLR that frees memory for objects nothing references any more.
JuniorWhat happens between writing C# code and it running on the CPU?

The C# compiler (Roslyn) type-checks the source and compiles it to IL, stored in an assembly (.dll) together with metadata. At run time the CLR loads the assembly, and the JIT compiler translates each method's IL to native machine code the first time it is called. The CLR also provides the garbage collector, type safety and exception handling. (Ahead-of-time options like Native AOT skip the JIT by compiling to native code at publish time.)

What they are really testing: Whether you know C# is compiled twice — to IL at build time and to native code at run time — rather than "compiled like C" or "interpreted like Python".

06

How a C# program is structured

The one-line app.cs uses top-level statements: code written directly in the file, which the compiler wraps in a hidden Main method for you. Older tutorials (and many real codebases) show the full form instead. Both compile to the same thing:

C#Program.cs
using System;

namespace HelloApp;

class Program
{
    static void Main(string[] args)
    {
        // Main is where the program starts
        Console.WriteLine("Hello from Main");
        Console.WriteLine($"Arguments passed: {args.Length}");
    }
}
Outputcompiled & run with real C#
Hello from Main
Arguments passed: 0

The classic entry point: a static Main method inside a class, inside a namespace.

  • using System; imports a namespace so you can write Console instead of System.Console. Modern projects turn on implicit usings, which import the common namespaces (System, System.Collections.Generic, System.Linq, System.IO…) automatically — that is why the one-liner needed no using.
  • namespace HelloApp; groups your types under a name so they do not clash with anyone else's. The semicolon form applies to the whole file.
  • class Program — all C# code lives inside a type. Top-level statements hide this; it is still there after compilation.
  • static void Main(string[] args) — the entry point. args holds command-line arguments.
  • // starts a comment to the end of the line; /* … */ spans lines; /// is an XML documentation comment that IDEs show on hover.

With top-level statements, your program's code comes first and any classes, records or other types you declare go after it. This is the style every example in this handbook uses:

C#Program.cs
/* Top-level statements run first, in order.
   Types are declared after them. */
var greeter = new Greeter("Ada");
greeter.SayHello();
Console.WriteLine(Greeter.Count);

/// <summary>Prints a greeting for one person.</summary>
class Greeter
{
    public static int Count = 0;
    private readonly string _name;

    public Greeter(string name)
    {
        _name = name;
        Count++;
    }

    public void SayHello() => Console.WriteLine($"Hello, {_name}!");
}
Outputcompiled & run with real C#
Hello, Ada!
1
Your turn

Create a second Greeter for another name, call SayHello on it, and check that Count now prints 2.

Error you will hit

CS0103: C# is case-sensitive

C#
console.WriteLine("Hello, World!");
Program.cs(1,1): error CS0103: The name 'console' does not exist in the current context
Why the compiler said that

The class is Console with a capital C. C# treats console and Console as two different names, and nothing called console exists. CS0103 is the error you get for any name the compiler cannot find — a typo, the wrong case, a missing using, or a variable used outside the block it was declared in.

The fix

Match the exact casing. By convention, types and methods are PascalCase and local variables are camelCase, so a lowercase console should look wrong to you.

C#
Console.WriteLine("Hello, World!");
Quick check

In a file that uses top-level statements, where do class declarations go?

07

How this handbook works

Seventeen modules, each its own page. The rail on the left lists them; the bar at the top and the pill at the bottom-left track how far you are. A lesson ticks itself when you reach its end, and the tick survives closing the tab — no account needed.

  • Examples are complete programs with the exact output they print. C# does not run in a browser, so nothing executes on this page — instead, every example was compiled and run with the real .NET SDK when the page was built, and the output shown is what it actually printed. Copy an example into app.cs, run dotnet run app.cs, and you will see the same thing. Then do its "Your turn" task.
  • Error cards are real compiler diagnostics (CSxxxx) and real runtime exceptions, copied from actually running the broken code. Module 11 collects the fifteen every beginner hits.
  • Traces step through a program line by line, showing what each variable holds — use them for loops, recursion and virtual dispatch.
  • Interview questions appear where the topic is taught and are collected in Module 15, tiered junior / mid / senior.
  • The handbook ends with a certification exam (Module 16 → exam): 25 questions, 70% to pass. Then the ATS resume checker with a real job posting.
The floating board
The pill at the bottom-left opens a board with this module's key concepts (from the glossary blocks), its error cards, and a tutor you can ask about any example. It is a language model — verify what it says with dotnet run.
08

Using AI to learn (without letting it learn for you)

An AI assistant can write a working C# class in seconds. That is exactly why you should type the examples yourself while learning: the goal is not the code, it is the model in your head of what the compiler checks, what lives on the stack and the heap, and which method actually runs — the model an interviewer is testing when they ask you to explain code on a whiteboard.

Do this

  • Paste a real CSxxxx error and ask what it means — then fix it yourself
  • Ask "why is this a value type and that a reference type"
  • Write the class first, then ask for a review
  • Ask for an edge case your method does not handle

Not this

  • Ask for the answer to a "Your turn" task and paste it in
  • Accept code you cannot explain line by line
  • Silence a nullable warning with ! because the AI suggested it
  • Use it in an interview (they can tell)

Ready? Module 01 starts with variables, the built-in types, and the difference between value types and reference types — the idea the rest of C# is built on.

Every lesson in the handbook

17 modules · 142 lessons · each one ticks itself when you reach the end.

00Getting Started0 / 8
01Fundamentals0 / 8
02Flow Control0 / 6
03Strings & Arrays0 / 7
04Methods0 / 8
05Classes & Objects0 / 8
06Inheritance & Interfaces0 / 7
07Exceptions0 / 8
08Collections & Generics0 / 7
09LINQ0 / 7
10Async & Await0 / 8
11Errors & Debugging0 / 7
12C# + Tools0 / 10
13Data Structures & Algorithms0 / 14
14Problem Solving0 / 12
15Interview Questions0 / 11
16Job Ready0 / 6

Frequently asked questions

Is this C# handbook free?
Yes — every module, every example and the certification exam are free, with no signup and no paywall. The exam asks you to sign in with Google so the certificate can carry your name.
Do I need to know another programming language first?
No. Module 01 starts from variables and types and assumes nothing. If you already know another language you will move faster, and the handbook calls out where C# differs, such as integer division, value types versus reference types, methods that are not virtual unless you say so, and nullable reference types.
Do I need to install anything?
Yes — the .NET SDK, and Module 00 shows how to install it and run your first program. The examples on this page do not run in the browser; instead, each example program was compiled and run with the .NET 10 SDK as a file-based app before publishing, and the output shown is exactly what it printed, so you can paste it into app.cs, run dotnet run app.cs and get the same result. The labs in Module 12 need NuGet packages and services such as ASP.NET Core, EF Core and PostgreSQL, so they are shown as clearly marked snippets.
Which version of C# and .NET does this handbook use?
.NET 10, the current long-term-support release, and C# 12 and later, including the modern features: records, primary constructors, switch expressions and pattern matching, nullable reference types, raw string literals and async streams. Every example is verified on the .NET 10 SDK, and older-version differences are pointed out where they matter.
Is there a certificate?
Yes. Pass the 25-question exam (35 minutes) with 70% or more and generate a SolutionGigs C# certificate with your name, score, date and a certificate ID — download it, print it or add it to LinkedIn.
How do I run a C# program?
Install the .NET SDK, save your code as app.cs and run dotnet run app.cs (.NET 10 and later). For a full project, run dotnet new console -o MyApp, then cd MyApp and dotnet run.
Is C# the same as .NET?
No. C# is the language; .NET is the platform it runs on — the runtime (CLR), the standard library and the SDK tools. .NET also runs F# and Visual Basic, and C# code compiles to the same IL they do.
Do I need Visual Studio to learn C#?
No. The free .NET SDK plus any editor is enough; VS Code with the C# Dev Kit extension works on every OS. Visual Studio (Windows) and JetBrains Rider are full IDEs you can move to later.

Finish the C# handbook, then get hired

Sit the exam for your certificate, run your resume through the ATS checker, and see the jobs that ask for exactly this.

Check my resume
Found this course useful? Share it.
ShareXLinkedIn

Comments

0

Join the conversation. Sign in to leave a comment — we'd love to hear your thoughts.