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