Format | Assembly Format | Description |
---|---|---|
90 | ldelem.i1 |
Load the element with type int8 at index onto the top of the stack as an int32 . |
92 | ldelem.i2 |
Load the element with type int16 at index onto the top of the stack as an int32 . |
94 | ldelem.i4 |
Load the element with type int32 at index onto the top of the stack as an int32 . |
96 | ldelem.i8 |
Load the element with type int64 at index onto the top of the stack as an int64 . |
91 | ldelem.u1 |
Load the element with type unsigned int8 at index onto the top of the stack as an int32 . |
93 | ldelem.u2 |
Load the element with type unsigned int16 at index onto the top of the stack as an int32 . |
95 | ldelem.u4 |
Load the element with type unsigned int32 at index onto the top of the stack as an int32 . |
96 | ldelem.u8 |
Load the element with type unsigned int64 at index onto the top of the stack as an int64 (alias for ldelem.i8 ). |
98 | ldelem.r4 |
Load the element with type float32 at index onto the top of the stack as an F |
99 | ldelem.r8 |
Load the element with type float64 at index onto the top of the stack as an F . |
97 | ldelem.i |
Load the element with type native int at index onto the top of the stack as a native int . |
9A | ldelem.ref |
Load the element at index onto the top of the stack as an O . The type of the O is the same as the element type of the array pushed on the CIL stack. |
…, array, index → …, value
The ldelem.<type>
instruction loads the value of the element with index index (of type int32
or native int
) in the zero-based one-dimensional array array and places it on the top of the stack. For ldelem.ref
the type of the return value is the element type of array, for the other instruction variants it is the <type> indicated by the instruction.
All variants are equivalent to the ldelem
instruction (§III.4.7) with an appropriate typeTok.
[Note: For one-dimensional arrays that aren't zero-based and for multidimensional arrays, the array class provides a Get
method. end note]
If required elements are converted to the representation of their intermediate type (§I.8.7) when loaded onto the stack (§III.1.1.1).
[Note: that is elements that are smaller than 4 bytes, a boolean or a character are converted to 4 bytes by sign or zero-extension as appropriate. Floating-point values are converted to their native size (type F
). end note]
System.NullReferenceException
is thrown if array is null.
System.IndexOutOfRangeException
is thrown if index is negative, or larger than the bound of array.
Correct CIL code requires that array is either null or a zero-based, one-dimensional array whose declared element type is array-element-compatible-with (§I.8.7.1) the type for this particular instruction suffix.
Verification requires that:
-
the tracked type of array is
T[]
, for someT
; -
for
ldelem.ref
T
is a reference type, for other instruction variantsT
is array-element-compatible-with the type in the instruction; and -
the type of index is
int32
ornative int
.
Verification tracks the type of the result value as T
for ldelem.ref
, or as the <type> in the instruction for the other variants.