C# Language — Basics to Advanced
What it is & where it is used
C# (pronounced "C sharp") is a modern, object-oriented, type-safe language created by Microsoft (lead designer Anders Hejlsberg) and standardised as ECMA-334. It compiles to IL (Intermediate Language) which the .NET runtime (CLR) turns into machine code with a JIT (or ahead of time with Native AOT).
Where C# is used:
- Web APIs and web apps — ASP.NET Core (MVC, Razor Pages, Web API, Blazor)
- Desktop — WPF, WinForms, .NET MAUI, WinUI
- Cloud and microservices — Azure Functions, containers, gRPC
- Games — Unity
- Data, ETL and background workers — Worker Services, console apps
Why interviewers care: almost every .NET round starts with C# fundamentals (value vs reference types, OOP, collections, LINQ, async) before moving to frameworks.
Versions & history
| C# | Year | .NET / Visual Studio | Headline features |
|---|---|---|---|
| 1.0 | 2002 | .NET Framework 1.0, VS.NET 2002 | Classes, structs, interfaces, events, properties, delegates |
| 2.0 | 2005 | .NET Framework 2.0, VS 2005 | Generics, nullable value types, iterators (yield), anonymous methods, partial types |
| 3.0 | 2007 | .NET Framework 3.5, VS 2008 | LINQ, lambda expressions, var, extension methods, anonymous types, auto-properties, object/collection initialisers |
| 4.0 | 2010 | .NET Framework 4.0, VS 2010 | dynamic, named and optional parameters, generic co/contravariance |
| 5.0 | 2012 | .NET Framework 4.5, VS 2012 | async / await, caller-info attributes |
| 6.0 | 2015 | VS 2015 (Roslyn compiler) | String interpolation, nameof, ?. null-conditional, expression-bodied members, exception filters |
| 7.0–7.3 | 2017–2018 | VS 2017 | Tuples, pattern matching, out var, local functions, ref returns, in parameters, Span<T> support |
| 8.0 | 2019 | .NET Core 3.0 | Nullable reference types, switch expressions, async streams, ranges ^1/.., default interface methods, using declarations |
| 9.0 | 2020 | .NET 5 | Records, init setters, top-level statements, target-typed new(), relational/logical patterns |
| 10 | 2021 | .NET 6 (LTS) | Global usings, file-scoped namespaces, record structs |
| 11 | 2022 | .NET 7 | Raw string literals, required members, list patterns, generic math (static abstract interface members) |
| 12 | 2023 | .NET 8 (LTS) | Primary constructors for classes, collection expressions [1, 2], alias any type |
| 13 | 2024 | .NET 9 | params collections, System.Threading.Lock, partial properties |
| 14 | 2025 | .NET 10 (LTS) | Extension members (extension blocks), the field keyword, null-conditional assignment a?.B = x |
Interview tip: you don't need every row. Know the big ones: generics (2.0), LINQ (3.0), async/await (5.0), nullable reference types (8.0), records (9.0), and the version you use at work.
Lifecycle
How a C# program runs
- Write
.csfiles inside a project (.csproj). - Build — the Roslyn compiler turns C# into IL plus metadata, packaged in an assembly (
.dll/.exe). - Load — the CLR loads the assembly, verifies the IL and resolves dependencies.
- JIT compile — each method is compiled to native code the first time it is called (tiered compilation re-optimises hot methods). Native AOT compiles everything ahead of time instead.
- Execute — managed code runs with type safety, exception handling and the garbage collector managing the heap.
- Unload / exit — finalisers and
IDisposablecleanup run; the process ends.
Object lifecycle: new → constructor runs → object lives on the managed heap while referenced → becomes unreachable → collected by the GC (Gen 0 → 1 → 2) → finaliser (if any) runs. Deterministic cleanup of unmanaged resources is done with Dispose() / using.
Tools used to develop
| Tool | Use |
|---|---|
| Visual Studio 2022/2026 (Windows) | Full IDE: debugger, profiler, designers, test explorer |
| Visual Studio Code + C# Dev Kit | Lightweight cross-platform editor |
| JetBrains Rider | Cross-platform IDE with strong refactoring |
.NET SDK / dotnet CLI | dotnet new, build, run, test, publish |
| NuGet | Package manager (dotnet add package) |
| LINQPad | Quick C#/LINQ scratchpad, great for interview practice |
| xUnit / NUnit / MSTest | Unit testing frameworks |
| BenchmarkDotNet | Micro-benchmarks |
| dotnet-trace, dotnet-counters, dotnet-dump | Diagnostics in production |
| ILSpy / SharpLab | See the IL and lowered C# the compiler produces |