Pages

Topics

Tools

↑↓navigate↵openescclose

C# guides

Every published C# guide, newest first, with practical examples you can copy into your own project.

3,965 guides across 14 topics

Topics

Latest C# guides

Illustration of C# concurrent collections representing thread-safe data structures with multiple threads accessing a shared collection.
C#

C# Concurrent Collections: Choosing the Right Thread-Safe Collection

Learn how to choose and use C# concurrent collections such as ConcurrentDictionary, ConcurrentQueue, ConcurrentStack, ConcurrentBag, and BlockingCollection, including code examples and common pitfalls.

C# ConcurrencyThread-Safe CollectionsSystem.Collections.ConcurrentProducer-Consumer
Illustration of multiple parallel threads each holding an isolated data container, representing ThreadLocal storage in C#.
C#

Using ThreadLocal<T> in C# for Per-Thread State

Learn how C# ThreadLocal<T> provides isolated per-thread state, when to use it instead of ThreadStatic or AsyncLocal, and how it affects memory and disposal.

ThreadLocalC# ConcurrencyThread SafetyAsyncLocal
A visual metaphor for the C# volatile keyword showing a memory barrier between threads and a shared field.
C#

C# volatile: Semantics and Practical Use

Understand what C# volatile does, when to use it, and its limits. Practical examples show correct usage and common pitfalls.

volatilememory modelthread safetyconcurrency
Diagram showing multiple threads performing an atomic increment on a single shared counter using C# Interlocked
C#

C# Interlocked: Atomic Operations Without Locks

c# interlocked: Learn how C# Interlocked provides atomic operations for thread-safe counters and lock-free updates without explicit locking.

Thread SafetyAtomic OperationsConcurrency.NET
A diagram showing the C# lock statement expanding into Monitor.Enter and Monitor.Exit calls around a critical section.
C#

C# Monitor vs Lock: When to Use Each

The lock statement compiles to Monitor.Enter and Monitor.Exit. Learn when the higher-level syntax is enough and when you need Monitor's advanced features like timeouts and thread signaling.

C#threadingconcurrencyMonitor
Two threads approaching a lock gate, one waiting while the other passes, illustrating C# lock object mutual exclusion
C#

C# Lock Object: Choosing What to Lock and Why

Choosing the right object for C#'s lock statement matters for thread safety. This article covers safe lock-object patterns, common mistakes, and how to avoid contention and deadlocks.

C#concurrencythread-synchronizationlock-statement
Illustration of C# thread safe lock concept showing multiple threads accessing a locked shared resource.
C#

C# Thread-Safe Locking: Choosing the Right Synchronization

Learn how to protect shared state in C# with lock, Monitor, Mutex, SemaphoreSlim, and ReaderWriterLockSlim, and avoid common concurrency pitfalls.

C#Thread SafetyLockingConcurrency
Illustration of a padlock protecting a shared data block while multiple threads wait in line, representing the C# lock keyword.
C#

Using the C# lock Keyword for Thread Safety

Understand the C# lock keyword: syntax, how it maps to Monitor, common pitfalls, performance impact, and when to use alternatives.

C# concurrencythread synchronizationlock statementMonitor class
Illustration of C# await using for asynchronous resource disposal with a shield and clock metaphor.
C#

C# await using: Asynchronous Resource Disposal

Learn how to use C# await using to dispose IAsyncDisposable resources asynchronously, with syntax, examples, and practical guidance.

IAsyncDisposableasync disposalresource managementC# using
Editorial illustration of an async iterator state machine streaming values from an asynchronous operation to a consumer loop.
C#

Using async yield return in C#

Combine async and yield return in C# with IAsyncEnumerable<T>. Learn await foreach, cancellation, error handling, and streaming behavior.

IAsyncEnumerableasync/awaitC# iteratorsawait foreach