|
|
Parameters
ref parameters:
+ |
One can use them to write methods with transient parameters, which are values
that are passed to a method, modified by the method, and returned to the caller.
If the same effect were to be achieved with functions one would have to use
both an input parameter and a function return value.
|
+ |
One can use them to write methods with multiple transient parameters.
With functions, one can have only a single return value.
|
+ |
The value of a ref parameter is not copied to the corresponding formal
parameter upon method call, but only a reference to the actual parameter
is passed. For large parameter objects this is more efficient than
passing the values of the objects.
|
- |
ref parameters can lead to side effects, because a formal ref parameter
is an alias of the corresponding actual ref parameter. If the method
modifies the formal ref parameter, the corresponding actual parameter
value changes as well.
|
out parameters:
+ |
One can use them to write methods with multiple output parameters.
With functions, one can have only a single return value.
|
+ |
Like ref parameters, out parameters are passed by reference. This
means that only a reference to the actual parameter is passed and not
its value. For large parameter objects this is more efficient than
returning the value as a function result.
|
+ |
The compiler makes sure that the invoked method assigns avlues
to all its out parameters.
|
- |
out parameters can lead to side effects, because a formal out parameter
is an alias of the corresponding actual out parameter. If the method
modifies the formal out parameter, the corresponding actual parameter
value changes as well.
|
Function return values:
+ |
There are no side effects. |
+ |
The return value can be ignored by the caller. However, this can also
be regarded as a disadvantage.
|
- |
A function method can have only a single return value. |
|