Stack Allocation
stackalloc Operator
- The natural type
stackallocreturns is the pointer of target element type(TUnmanaged*). - Element type must be unmanaged type.
- Similar to
newoperator, compiler can infer the target type;
cs
_ = stackalloc int[] { 1, 2, 3 };
_ = stackalloc[] { 1d, 2d, 3f };
_ = stackalloc byte[10];1
2
3
2
3