Skip to content

Commit 1d4df0d

Browse files
Nigel-Ecmajskeet
authored andcommitted
Update expressions.md
Squeeze a definition of Span<T> into the description of stackalloc as it is not defined elsewhere.
1 parent 877c2ee commit 1d4df0d

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

standard/expressions.md

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3118,11 +3118,13 @@ When a *stackalloc_initializer* is present:
31183118

31193119
Each *stackalloc_element_initializer* shall have an implicit conversion to *unmanaged_type* ([§10.2](conversions.md#102-implicit-conversions)). The *stackalloc_element_initializer*s initialize elements in the allocated memory in increasing order, starting with the element at index zero. In the absence of a *stackalloc_initializer*, the content of the newly allocated memory is undefined.
31203120

3121-
The result of a *stackalloc_expression* is an instance of type `Span<T>`, where `T` is the *unmanaged_type* and the instance’s `Length` property returns the number of items allocated.
3121+
The result of a *stackalloc_expression* is an instance of type `Span<T>`, where `T` is the *unmanaged_type*:
31223122

3123-
> *Note*: When occurring in unsafe code the result of a *stackalloc_expression* may be of a different type, see ([§23.9](unsafe-code.md#239-stack-allocation)). *end note*
3123+
- `Span<T>` ([§C.3](standard-library.md#c3-standard-library-types-not-defined-in-isoiec-23271)) is a ref struct type ([§16.2.3](structs.md#1623-ref-modifier)), which presents a block of memory, here the block allocated by the *stackalloc_expression*, as an indexable collection of typed (`T`) items.
3124+
- The result’s `Length` property returns the number of items allocated.
3125+
- The result’s indexer ([§15.9](classes.md#159_indexers)) returns a *variable_reference* ([§9.5](variables.md#95-variable-references)) to an item of the allocated block and is range checked.
31243126

3125-
Access via an instance of `Span<T>` to the elements of an allocated block is range checked.
3127+
> *Note*: When occurring in unsafe code the result of a *stackalloc_expression* may be of a different type, see ([§23.9](unsafe-code.md#239-stack-allocation)). *end note*
31263128
31273129
Stack allocation initializers are not permitted in `catch` or `finally` blocks ([§13.11](statements.md#1311-the-try-statement)).
31283130

0 commit comments

Comments
 (0)