C# Advanced tutorial
Write asynchronous, concurrent and modern C#: async/await, threads, records, pattern matching, reflection, attributes, dynamic types, expression trees, dependency injection, memory management, nullable reference types, logging and HttpClient.
Course contents
Asynchronous Programming
- Async Programming — Wait without freezing: Task, Task<T>, async and await, how await really runs, return types, ValueTask, async void, exceptions, and async file and network calls.
- Task Coordination — Run many tasks together: Task.WhenAll, Task.WhenAny, results, errors from many tasks, timeouts, throttling, retries and common async patterns.
- Cancellation — Stop async work with CancellationToken and timeouts, use ConfigureAwait and avoid blocking, and stream data with IAsyncEnumerable and await foreach.
Multithreading
- Threading — Threads and processes, creating threads, the lifecycle, foreground and background threads, the thread pool, Task.Run, CPU vs I/O work and error handling.
- Synchronization — Keep shared data safe: race conditions, critical sections, the lock statement, Interlocked, deadlocks, thread safety and synchronization strategies.
- Concurrent Collections — Share data between threads without locks: ConcurrentDictionary, ConcurrentQueue, ConcurrentStack, ConcurrentBag, producer-consumer, caching and data processing.
- Parallel Programming — Use every CPU core: Parallel.For, ForEach and Invoke, thread-local data, PLINQ, degree of parallelism, stopping loops, errors, performance and concurrency.
Modern C# Features
- Advanced Generics — Generic constraints with where: new(), interface and base class constraints, multiple constraints, generic math with INumber<T>, and generic performance.
- Extension Methods — Add methods to existing types with the this modifier: extend built-in types, your own types and interfaces, chain calls, and know when to use them.
- Records — Data types that compare by value: record declaration, value equality, immutability, init, with, positional records, record classes and record structs.
- Pattern Matching — Test the shape of data: type, constant, relational, logical, property, positional, tuple, list, var and discard patterns, and switch expressions.
- Modern C# Features — Write less code with fewer mistakes: required members, primary constructors, ranges and indexes, collection expressions, raw strings and more.
Reflection and Metadata
- Reflection — Look inside types at runtime: the Type class, members, reading and setting properties and fields, calling methods, creating objects, generics, assemblies and performance.
- Attributes — Label code with attributes: built-in attributes, Obsolete, Conditional, caller information, parameters, custom attributes, targets, reading them with reflection and validation.
- Dynamic Types — Resolve members at runtime with dynamic: runtime binding, dynamic member access and calls, ExpandoObject, DynamicObject, unknown data, reflection vs dynamic and performance.
- Expression Trees — Store code as data: Expression and lambda trees, building nodes by hand, compiling and executing, ExpressionVisitor, dynamic queries, IQueryable and how ORMs translate to SQL.
Dependency Injection and Configuration
- Dependency Injection — Hand classes what they need: dependency inversion, constructor, method and property injection, registration and resolution, singleton, scoped and transient lifetimes, factories and multiple implementations.
- Configuration and Options — Read settings from JSON, environment variables and the command line, layer them, bind sections to classes, and use IOptions, IOptionsSnapshot, IOptionsMonitor, validation and reloading.
Memory Management
- Garbage Collection — How .NET frees memory for you: managed heap, allocation, generations, the Large Object Heap, reachability, GC roots, forcing collections, managed memory leaks and performance.
- Resource Management — Release files, connections and other resources on time: IDisposable, the dispose pattern, using statements and declarations, finalizers, SuppressFinalize, IAsyncDisposable and await using.
- High-Performance Memory — Work with memory without copying: Span, ReadOnlySpan, Memory, ReadOnlyMemory, stackalloc, slicing, buffer operations, ArrayPool and reducing garbage collection pressure.
Advanced Development
- Nullable Reference Types — Make null visible to the compiler: nullable context, string vs string?, warnings, null checks, !, ??, ??=, nullable attributes, legacy code and avoiding NullReferenceException.
- Logging — Record what your app does: ILogger, log levels, structured logging, providers, console and file logging, exception logging, diagnostics, debugging, tracing and metrics.
- HttpClient and JSON — Call web APIs and handle JSON: HttpClient, GET, POST, PUT and DELETE, headers, responses, System.Text.Json serialization, options, attributes, typed clients and error handling.