Partager via


Differences Between Modifiable and Nonmodifiable Arguments (Visual Basic)

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

Enumeration members

Array elements

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 ByRef (Visual Basic), 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 ByVal (Visual Basic). 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.

See Also

Tasks

How to: Pass Arguments to a Procedure (Visual Basic)

How to: Change the Value of a Procedure Argument (Visual Basic)

How to: Protect a Procedure Argument Against Value Changes (Visual Basic)

How to: Force an Argument to Be Passed by Value (Visual Basic)

Concepts

Procedures in Visual Basic

Procedure Parameters and Arguments (Visual Basic)

Passing Arguments by Value and by Reference (Visual Basic)

Differences Between Passing an Argument By Value and By Reference (Visual Basic)

Passing Arguments by Position and by Name (Visual Basic)

Value Types and Reference Types