概要:
如果一个参数对应的元素是可修改的,那这个参数也是可修改的。你使用 ByRef 传递方式,就可以 修改参数对应的元素。
不可修改的参数包含两种情况:1. 该参数对应的元素本身不可修改。(可修改和不可修改的元素详见下表)。2. 虽然参数对应的元素本身可修改,但是使用 ByVal 作为参数传递方式。
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.
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) |
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.
上一页: 当参数是 Reference type 时使用 ByVal 和 ByRef 的区别 返回上级目录: VB.NET 的参数传递机制 下一页: Parameters and Arguments 的区别
© 2008 HubaPo.com 版权所有 Contact me