Skip to content

Memory and Performance in C#

Every page here is directly about reducing allocations or working closer to memory and references.

FeatureIntroduced InWhy it belongs hereGuide
Span<T>C# 7.2Allocation-free slices over contiguous memory.Guide
Implicit Span and ReadOnlySpan conversionsC# 14.0Reduces friction when passing arrays and spans to span-first APIs.Guide
ref structC# 7.2Stack-only type foundation for Span<T>.Guide
ref localsC# 7.0Alias storage locations without copying values.Guide
ref returnsC# 7.0Return references instead of copied values.Guide
readonly structC# 7.2Prevent defensive copies for immutable value types.Guide
Generic mathC# 11.0Zero-boxing numeric abstractions via static interfaces.Guide