Skip to main content
Journey Uncommon Logo
JourneyUncommon
hardC#Span and MemorySingle-choice MCQ

A method receives a Span<T> over a stackalloc buffer and tries to store it in a field of a class. Why does this fail to compile, and what runtime guarantee does the rule protect?

class Holder { Span<int> _field; void Set() { Span<int> s = stackalloc int[4]; _field = s; // does this compile? } }