Skip to main content
Journey Uncommon Logo
JourneyUncommon
hardC#stackalloc and the stackSingle-choice MCQ

Why can a `Span<T>` that wraps `stackalloc` memory never be stored in a field of a class, returned from the method, or captured by a lambda?

Span<int> Bad() { Span<int> s = stackalloc int[4]; return s; // compile error }