Differences Between Modifiable and Nonmodifiable Arguments
When you call a procedure, you typically pass one or more arguments to it. Each argument corresponds to an underlying programming element. Both the underlying elements and the arguments themselves can be either modifiable or nonmodifiable.
Modifiable and Nonmodifiable Elements
A programming element can be either a modifiable element, which can have its value changed, or a nonmodifiable element, which has a fixed value once it has been created.
The following table lists modifiable and nonmodifiable programming elements.
|Modifiable elements||Nonmodifiable elements|
Local variables (declared inside procedures), including object variables, except for read-only
Read-only variables, fields, and properties
Fields (member variables of modules, classes, and structures), except for read-only
Constants and literals
Properties, except for read-only
Expressions (even if their elements are modifiable)
Modifiable and Nonmodifiable Arguments
A modifiable argument is one with a modifiable underlying element. The calling code can store a new value at any time, and if you pass the argument, the code in the procedure can also modify the underlying element in the calling code.
A nonmodifiable argument either has a nonmodifiable underlying element or is passed. The procedure cannot modify the underlying element in the calling code, even if it is a modifiable element. If it is a nonmodifiable element, the calling code itself cannot modify it.
The called procedure might modify its local copy of a nonmodifiable argument, but that modification does not affect the underlying element in the calling code.