Compartilhar via


Diferenças entre argumentos modificáveis e não modificáveis (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.

Consulte também

Tarefas

Como: Passar argumentos para um procedimento (Visual Basic)

Como: Alterar o valor de um argumento de procedimento (Visual Basic)

Como: Proteger um argumento de procedimento contra alterações de valor (Visual Basic)

Como: forçar um argumento a ser passado por valor (Visual Basic)

Conceitos

Procedimentos no Visual Basic

Parâmetros e argumentos de procedimento (Visual Basic)

Passando argumentos por valor e por referência (Visual Basic)

Diferenças entre passar um argumento por valor e por referência (Visual Basic)

Passagem de argumentos por posição e nome (Visual Basic)

Outros recursos

Implementação de tipos de dados (Visual Basic)