Learn C# – tutorial, cheatsheet & exercises
C# (pronounced "C Sharp") is Microsoft's modern, statically typed general-purpose language. It runs on .NET, is cross-platform (Windows, macOS, Linux) and combines clear object-oriented concepts with functional elements such as LINQ, records and pattern matching.
Typical use cases: game development with Unity, web APIs and websites with ASP.NET Core, desktop applications, cloud services on Azure and enterprise software. The compiler (Roslyn) and the tooling support are excellent – you usually spot errors while you are still typing. This course uses modern C# 12 with .NET 8.
Hello World in C#
Console.WriteLine("Hello World!");Thanks to top-level statements, a single line is enough – no class and no Main needed.
How to get started with C#
Install the .NET SDK (version 8 or newer) from dotnet.microsoft.com/download – on the Mac with brew install --cask dotnet-sdk, on Windows with winget install Microsoft.DotNet.SDK.8. Check the installation in the terminal:
dotnet --versionYou create a new console project with a single command and start it with dotnet run:
dotnet new console -o HalloCSharp
cd HalloCSharp
dotnet runThe folder contains Program.cs (your code, using so-called top-level statements without a Main method) and HalloCSharp.csproj (project file with the target framework and settings such as Nullable). You add packages with dotnet add package Name, and dotnet watch restarts the program automatically whenever you save.
dotnet run -- Ada --laut.Console.WriteLine works, console.writeline does not. Every statement ends with a semicolon.C# learning path
Hello World & Top-Level Statements
Your first C# program and how output works.
Variables & Data Types
Numbers, text, booleans, var and conversions.
Conditions: if, switch & Co.
Making decisions in code, including with switch expressions.
Loops: for, foreach, while
Repeating tasks – over numbers and collections.
Methods
Reusable building blocks of code with parameters and return values.
Arrays, Lists, Dictionaries, Sets
The most important collection types and how to use them.
Classes, Inheritance & Records
Custom data types with properties, behavior and value semantics.
Nullable Reference Types
Catch null errors at compile time.
LINQ: Querying Data
Filter, transform, sort and group with one consistent syntax.
Error Handling & Files
Exceptions, custom error types and working safely with files.
Pattern Matching
Elegantly test and deconstruct types, properties and structures.
async/await & Tasks
Concurrent I/O without blocked threads.
Interfaces & Generics
Define contracts and write type-safe, reusable code.
Delegates, Lambdas & Events
Pass functions as values and react to events.
Value Types, IDisposable & Span
How memory, copies and resources work in .NET.
Modern C# 10–12
Primary constructors, collection expressions, raw strings and more.
At a glance
More about C#
Test & practice
Interactive quiz, timed exam with certificate, and exercises with an editor: