SYNTAX

stackalloc expression

Allocates bounded stack storage; initialize before reading.

Formal Syntax & Structure

csharp syntaxcsharp
Span<int> scratch = stackalloc int[3];

Working Example

Example Snippetcsharp
// Documentary fragment; see linked lesson for context.Span<int> scratch = stackalloc int[3];
C# & .NET Reference