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

stackalloc int[1024] is assigned to a Span<int>. What does the runtime actually do, and what is the main safety guarantee the Span provides over a classic int* from stackalloc?

Span<int> buf = stackalloc int[1024]; buf[1023] = 42; // fine // buf[2000] = 1; // throws IndexOutOfRangeException instead of corrupting the stack