Pages

Topics

Tools

↑↓navigate↵openescclose

All syntax guides

Short, practical guides on programming syntax, language fundamentals, and the tools developers reach for every day.

3,980 guides across 14 topics

Topics

Latest guides

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
Illustration of a C# async iterator streaming values with yield return and await foreach
C#

C# Async Iterator: yield return and await foreach

c# async iterator: Learn how to create and consume C# async iterators using IAsyncEnumerable, yield return, and await foreach with practical examples.

C#AsyncIAsyncEnumerableyield return
Illustration of an asynchronous stream being consumed by a foreach loop with an await keyword, symbolizing c# await foreach.
C#

Using C# await foreach with IAsyncEnumerable

Learn how to consume and produce asynchronous streams with C# await foreach, including cancellation, error handling, and runtime requirements.

async streamsIAsyncEnumerableC# 8asynchronous programming
Illustration of a C# async stream pipeline with data flowing through sequential processing stages
C#

Using C# IAsyncEnumerable for Async Streams

Learn how to produce and consume async streams with C# IAsyncEnumerable, including await foreach, cancellation, error handling, and resource management.

C#async/awaitstreamingIEnumerable
Illustration of a C# async enumerable streaming data items from a source to a consumer with await foreach.
C#

Using C# Async Enumerable for Streaming Data

Learn how to create and consume async enumerables in C# using IAsyncEnumerable<T> and await foreach, including cancellation and resource management.

IAsyncEnumerableasync streamsawait foreachC# async