Passing Arguments to Custom Methods

Although the way you pass arguments to methods is the same as passing arguments to other functions or subroutines, you should consider whether the class will be running in or out of the calling application's process.

If the method and calling statement are in the same process, generally you should pass arguments by reference, using the ByRef keyword. Within the same process, ByRef simply passes a reference to the variable, which in the main is more efficient that passing a copy of the variable's value, as ByVal does.

However, if there is a process boundary to be crossed, ByRef actually makes a copy of the value that it passes to the called procedure. When the called procedure terminates, it also makes a copy of the value to pass back to the calling procedure. The calling procedure then copies the returned value into the original value's address in memory. This means that if you are passing arguments across process boundaries, passing arguments by value with the ByVal keyword is more efficient.

M

l

l

s

to

Implementing Custom Class Methods 69

Was this article helpful?

0 0

Post a comment