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,965 guides across 14 topics

Topics

Latest guides

Visual comparison of C# Memory and Span showing a safe managed reference versus a stack-like view.
C#

C# Memory vs Span: Choosing the Right Approach

c# memory vs span: Understand the differences between Memory<T> and Span<T> in C#, including when to use each, their runtime behavior, and practical guidance for high-...

C# Span<T>Memory<T>Memory ManagementPerformance
Iconic representation of a stack memory buffer with a C# Span pointer, symbolizing zero-allocation temporary buffers.
C#

Using C# Span with Stackalloc for Zero-Allocation Buffers

Learn how to use C# Span<T> with stackalloc for zero-allocation temporary buffers: syntax, constraints, practical examples, and when to avoid stack allocation.

Span<T>stackallocmemory managementperformance
Diagram of a stack frame with a stackalloc buffer shown in green, highlighting the brief lifetime of the allocated memory.
C#

Using C# stackalloc for High-Performance Buffers

Learn how to use c# stackalloc to allocate buffers on the stack, avoid heap allocations, and improve performance in high-frequency code paths.

C#stackallocSpan<T>memory management
Illustration of a C# Span slicing a byte array into segments without copying memory.
C#

Slicing Spans in C#

Learn how to use Span<T>.Slice to create memory views without allocations, with practical examples and performance considerations.

Span<T>C# performanceMemory managementSlicing
Diagram showing a ReadOnlySpan pointing to a slice of a character array without copying.
C#

Using ReadOnlySpan in C# for Slicing and Validation

ReadOnlySpan in C# enables allocation-free slicing and validation of strings and buffers. Includes practical parsing examples, ref struct restrictions, and performance trade-offs.

ReadOnlySpanMemory ManagementSpan<T>High-Performance C#
Diagram comparing a C# array and a Span<T> view over the same memory block, highlighting zero-copy slicing.
C#

C# Span vs Array: Choosing the Right Type

Learn the practical differences between Span<T> and arrays in C#, including memory allocation, performance, and when to use each type.

Span<T>ArrayMemory ManagementC# Performance
Visual comparison of C# string and Span<T> showing a string as a contiguous block and a span as a view into that block.
C#

C# Span vs String: When to Use Each for Performance

Compare Span<T> and string in C# for memory efficiency and performance. Learn when to use each, how they differ, and see practical examples.

Span<T>stringmemory allocationperformance
Illustration of C# scoped ref limiting a reference lifetime within a method boundary.
C#

C# scoped ref: Controlling Reference Lifetimes

C# scoped ref: Learn how the scoped modifier in C# restricts reference lifetimes, prevents unsafe escapes, and improves safety with ref structs like Span<T>.

C#ref structscoped modifierSpan
Diagram comparing C# in, ref, and out parameter modifiers with arrows showing data flow.
C#

C# in vs ref vs out: Parameter Passing Explained

Learn how C# in, ref, and out parameter modifiers differ, when to use each, and how they affect method signatures and runtime behavior.

C#parameter modifiersrefout
Illustration of a readonly reference pointing to a struct in memory, with a lock icon indicating read-only access
C#

Understanding readonly ref in C#

Learn how readonly ref in C# lets you return and pass large structs by reference without mutation, reducing copies and improving performance.

C#ref returnsreadonly structsperformance