What is the difference between ByRef and Output method argument modifiers?

482 Views Asked by At

All is in the subject, really.

I fail to see what the difference in behavior is between those two methods for x:

// first version
Method m(ByRef x As whatever)
{
    // play with x
}

// second version
Method m(Output x As whatever)
{
    // play with x
}

There must be some reason why both those modifiers exist, however my "mastery" (uhm) of the language is not enough to understand the difference. I have tried and read the documentation, search it etc, to no avail so far.

So, what is the difference between those two argument modifiers?

1

There are 1 best solutions below

0
On BEST ANSWER

Well those are just "prettifiers", they don't do much in terms of actual language behaviour, and only used to provide documentation. Idea is that arguments documented as ByRef provide both input and output, for example you can pass an array to be sorted, and Output arguments only provide output, for example list of errors. Output modifier was introduced later, and a lot of system code still use ByRef for both use cases.

If argument is actually passed by reference is only determined by method caller, and keyword doesn't really matter. You will call your method as ..m(.parameter) to pass variable by reference, and ..m(parameter) to pass variable by value.