共用方式為


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

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, 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. 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
How to: Change the Value of a Procedure Argument
How to: Protect a Procedure Argument Against Value Changes
How to: Force an Argument to Be Passed by Value

Concepts

Procedures in Visual Basic
Procedure Parameters and Arguments
Argument Passing By Value and By Reference
Differences Between Passing an Argument By Value and By Reference
Argument Passing by Position and by Name
Value Types and Reference Types