C# Tutorial with Examples.
C# tutorial: modern C# language features, .NET enterprise applications, Azure ecosystem integrations and desktop software, with real output.
Beginner
Start here — no prior experience needed
Introduction to C#
Learn what C# is, how the .NET ecosystem works, and where C# is used in the real world.
Setting Up C# Development Environment
Install the .NET SDK, configure VS Code with the C# extension, and run your first C# program.
Variables in C#
Understand var, explicit types, nullable reference types, const, and readonly in C#.
Data Types in C#
Understand value types vs reference types, structs, records, and boxing/unboxing in C#.
Operators in C#
Master arithmetic, null-coalescing, null-conditional, and pattern matching operators in C#.
Control Flow in C#
Master if/else, switch expressions, for/foreach/while loops, and pattern matching in C#.
Functions and Methods in C#
C# methods by example: value, ref, out and params parameters, optional and named arguments, overloading, local functions, tuples and extension methods.
Strings in C#
C# strings by example: immutability, interpolation and format specifiers, verbatim and raw literals, StringBuilder, Span<char> parsing and Regex.
Arrays in C#
C# arrays by example: fixed-size declaration, indices and ranges, rectangular vs jagged arrays, Array.Sort and BinarySearch, LINQ, and Span<T> slices.
Arrays and Collections in C#
C# collections by example: List<T>, Dictionary<K,V>, HashSet<T>, Queue, Stack, PriorityQueue and lazy IEnumerable<T>, with real output from each.
Object-Oriented Programming in C#
C# object-oriented programming by example: classes, constructors, properties, encapsulation, inheritance, virtual/override, abstract and sealed classes.
Intermediate
For developers with core concepts down
Records in C#
Positional records, value-based equality, non-destructive mutation with with, and record struct in C#.
Interfaces in C#
C# interfaces by example: implementing contracts, segregation, explicit implementation, default interface methods, and swapping implementations for tests.
Generics in C#
C# generics by example: generic classes and methods, where constraints, static abstract members, a Result<T> type, and covariance vs contravariance.
LINQ in C#
LINQ in C# by example: query vs method syntax, filtering, ordering, GroupBy, Join and left join, SelectMany, deferred execution and IQueryable.
Async/Await in C#
C# async/await by example: what await really does, Task.WhenAll vs sequential awaits, throttling, cancellation, ValueTask, async streams, async void.
Delegates, Events, and Lambdas in C#
C# delegates by example: Func, Action and Predicate, lambdas and closures, multicast invocation, events and EventHandler<T>, and delegates as strategies.
Error Handling in C#
C# error handling by example: try/catch/finally, using and Dispose order, exception filters, custom exceptions, throw vs throw ex, and AggregateException.
File I/O in C#
C# file I/O by example: the File and Directory classes, Path, StreamReader and StreamWriter, async reads, System.Text.Json, and FileSystemWatcher.
Pattern Matching in C#
C# pattern matching by example: type, constant, relational, property, positional and list patterns, switch expressions, and exhaustiveness warnings.
Testing in C#
Testing C# with xUnit by example: Fact and Theory, readable failures with FluentAssertions, Moq mocks and Verify, fixtures, async tests, and NUnit.
ASP.NET Core Basics
ASP.NET Core by example: minimal APIs, a CRUD API driven with curl, controllers and validation, middleware order, exception handling, DI and config.
Entity Framework Core
EF Core by example on SQLite: DbContext and model, the SQL each LINQ query generates, Include vs N+1, change tracking, bulk updates, migrations.
Advanced
Production-grade patterns for experienced engineers
Design Patterns in C#
C# design patterns by example: Singleton with Lazy<T> and DI lifetimes, Repository, a hand-rolled Mediator, Decorator for caching, and Strategy.
Performance in C#
High-performance C# by example: BenchmarkDotNet, Span<T> parsing, Memory<T>, ArrayPool, struct vs class, string.Create and SIMD, with measured results.
C# Interview Preparation
35 C# interview questions answered, with runnable proof for the tricky ones: boxing, override vs new, == vs Equals, deadlocks, and lost updates.