Format | Assembly Format | Description |
---|---|---|
80 <T> | stsfld field |
Replace the value of field with val. |
…, val → …,
The stsfld
instruction replaces the value of a static field with a value from the stack. field is a metadata token (a fieldref
or fielddef
; see Partition II) that shall refer to a static field member. stsfld
pops the value off the stack and updates the static field with that value.
Storing into fields that hold a value smaller than 4 bytes truncates the value as it moves from the stack to the local variable. Floating-point values are rounded from their native size (type F
) to the size associated with the argument. (See §III.1.1.1, Numeric data types.)
The stsfld
instruction can have a volatile.
prefix.
System.FieldAccessException
is thrown if field is not accessible.
System.MissingFieldException
is thrown if field is not found in the metadata. This is typically checked when CIL is converted to native code, not at runtime.
Correct CIL ensures that field is a valid token referring to a static field, and that value will always have a type appropriate for the assignment being performed, subject to implicit conversion as specified in §III.1.6.
Verification checks that the type of val is verifier-assignable-to the type of the field.
[Note: Using stsfld
to change the value of a static, init-only field outside the body of the class initializer can lead to unpredictable behavior. It cannot, however, compromise memory integrity or type safety so it is not tested by verification. end note]