Span<T> and Memory<T>
Explain Span<T> vs Memory<T> and when each is used.
Answers use simple, clear English.
Quick interview answer
Span<T> is a ref struct that can point to stack, array, or unmanaged memory with zero allocation slicing, but cannot be stored on the heap or used across async awaits. Memory<T> is heap-compatible and can be stored/passed across async boundaries; you get a Span via Memory.Span when needed.
Detailed answer
Span<T> is a ref struct that can point to stack, array, or unmanaged memory with zero allocation slicing, but cannot be stored on the heap or used across async awaits. Memory<T> is heap-compatible and can be stored/passed across async boundaries; you get a Span via Memory.Span when needed. These types enable high-performance parsing and buffer handling without copying. ASP.NET Core Kestrel and System.Text.Json use them heavily.
Full explanation
These types enable high-performance parsing and buffer handling without copying. ASP.NET Core Kestrel and System.Text.Json use them heavily.