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.

Start the course

Course contents

Asynchronous Programming

  1. 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.
  2. Task Coordination — Run many tasks together: Task.WhenAll, Task.WhenAny, results, errors from many tasks, timeouts, throttling, retries and common async patterns.
  3. Cancellation — Stop async work with CancellationToken and timeouts, use ConfigureAwait and avoid blocking, and stream data with IAsyncEnumerable and await foreach.

Multithreading

  1. 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.
  2. Synchronization — Keep shared data safe: race conditions, critical sections, the lock statement, Interlocked, deadlocks, thread safety and synchronization strategies.
  3. Concurrent Collections — Share data between threads without locks: ConcurrentDictionary, ConcurrentQueue, ConcurrentStack, ConcurrentBag, producer-consumer, caching and data processing.
  4. 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

  1. Advanced Generics — Generic constraints with where: new(), interface and base class constraints, multiple constraints, generic math with INumber<T>, and generic performance.
  2. 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.
  3. Records — Data types that compare by value: record declaration, value equality, immutability, init, with, positional records, record classes and record structs.
  4. Pattern Matching — Test the shape of data: type, constant, relational, logical, property, positional, tuple, list, var and discard patterns, and switch expressions.
  5. 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

  1. Reflection — Look inside types at runtime: the Type class, members, reading and setting properties and fields, calling methods, creating objects, generics, assemblies and performance.
  2. Attributes — Label code with attributes: built-in attributes, Obsolete, Conditional, caller information, parameters, custom attributes, targets, reading them with reflection and validation.
  3. Dynamic Types — Resolve members at runtime with dynamic: runtime binding, dynamic member access and calls, ExpandoObject, DynamicObject, unknown data, reflection vs dynamic and performance.
  4. 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

  1. 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.
  2. 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

  1. 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.
  2. Resource Management — Release files, connections and other resources on time: IDisposable, the dispose pattern, using statements and declarations, finalizers, SuppressFinalize, IAsyncDisposable and await using.
  3. High-Performance Memory — Work with memory without copying: Span, ReadOnlySpan, Memory, ReadOnlyMemory, stackalloc, slicing, buffer operations, ArrayPool and reducing garbage collection pressure.

Advanced Development

  1. Nullable Reference Types — Make null visible to the compiler: nullable context, string vs string?, warnings, null checks, !, ??, ??=, nullable attributes, legacy code and avoiding NullReferenceException.
  2. Logging — Record what your app does: ILogger, log levels, structured logging, providers, console and file logging, exception logging, diagnostics, debugging, tracing and metrics.
  3. 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.