Introduction to C#
C# (pronounced "C sharp") is a modern, general-purpose language from Microsoft that runs on the free, open-source .NET platform. You can use it to build web APIs, cloud services, desktop and mobile apps, command-line tools and games — on Windows, macOS and Linux. This course teaches C# 14 on .NET 10, the current long-term-support release.
What C# looks like
Here is a complete C# program. It stores a few prices in a list, adds them up and prints a summary:
List<decimal> prices = [4.50m, 12.99m, 3.25m]; decimal total = 0; foreach (decimal price in prices) { total += price; } Console.WriteLine($"{prices.Count} items, total {total}");
3 items, total 20.74
Even if you've never seen C# before, you can probably follow it: a list of numbers, a loop that adds them, and a line of output. By the end of lesson 3 you'll run programs like this yourself.
Why learn C#?
- One language, many targets. The same skills cover web back ends (ASP.NET Core), cloud functions, desktop apps, cross-platform mobile apps (.NET MAUI), command-line tools and game scripting in engines such as Unity and Godot.
- Safe by default. C# is statically typed and memory-managed: the compiler catches type mistakes before the program runs, and a garbage collector frees memory you no longer use. Nullable reference types (lesson 43) even warn you about many null-reference bugs at compile time.
- Productive. Features like LINQ (lesson 49),
async/await(lesson 57), records and pattern matching let you express a lot in a little code. - Fast. .NET compiles your code to native machine code as it runs and is among the fastest managed runtimes available.
- In demand. C# is used heavily in enterprise software, finance, healthcare and the games industry, so it's a valuable language for your career.
C# and .NET
C# is the language; .NET is the platform your programs run on. When you install the .NET SDK (next lesson) you get:
| Part | What it does |
|---|---|
| The C# compiler (Roslyn) | Checks your code and translates it into IL (intermediate language), a compact instruction format stored in a .dll file. |
| The runtime (CLR) | Loads the IL and compiles it to native machine code just in time (the JIT), manages memory with a garbage collector and handles exceptions. |
| The base class library | Thousands of ready-made types: strings, collections, files, networking, JSON, dates, threads and much more. |
The dotnet command | Creates, builds, runs, tests and publishes your programs. |
Because programs are compiled to IL rather than straight to one processor's code, the same compiled program runs on any operating system that has the .NET runtime. You can also publish a self-contained or natively compiled (Native AOT) version that needs no runtime installed.
A short history
| Year | Milestone |
|---|---|
| 2002 | C# 1.0 ships with the original .NET Framework, which ran only on Windows. The language was designed by a team led by Anders Hejlsberg. |
| 2005–2012 | Generics (C# 2), LINQ and lambdas (C# 3), dynamic (C# 4) and async/await (C# 5). |
| 2016 | .NET Core 1.0: a rewritten, open-source, cross-platform .NET for Windows, macOS and Linux. |
| 2020 | .NET 5 unifies the platform under one name; C# 9 adds records and top-level statements. |
| 2021–2024 | C# 10–13: file-scoped namespaces, raw string literals, required members, primary constructors and collection expressions. |
| 2025 | .NET 10 (long-term support) and C# 14: extension members, the field keyword, null-conditional assignment, and running a single .cs file directly with dotnet run. |
A new major version of .NET ships every November. Even-numbered releases such as .NET 10 are long-term support (LTS, three years of updates); odd-numbered ones are standard-term support (STS). Most production code targets the latest LTS, which is why this course uses .NET 10.
How C# compares
- Java: very similar syntax and goals. C# adds properties, value types (
struct), LINQ,async/awaitand many conveniences; the two are easy to switch between. - C and C++: C# borrows their syntax but manages memory for you, so you don't allocate and free memory by hand.
- Python and JavaScript: C# is statically typed and compiled, so many errors are caught before the program runs, and code completion in editors is very precise.
- TypeScript: designed by the same lead designer, so much will feel familiar.
How this course works
Each lesson explains one topic with short, complete programs and their exact output. Every example was compiled and run with the .NET 10 SDK, and the output you see is what it printed. Most lessons end with a Try it yourself editor: change the code, press Copy, paste it into a file and run it with dotnet run.
Lessons build on each other, so work through them in order the first time. The quiz, exercises and syllabus pages at the end of the sidebar help you check your progress.