I come from a C# background so I’m not quite up to snuff on my VB just yet.
I’ve run across this practice all over our code base and it is never used for chaining.
I am wondering what performance consequences (if any) this might create.
Public Function Save(ByRef myObj As MyBusinessObject) As MyBusinessObject
'Do save stuff
'Return object we just saved
Return myObj
End Function
'usage
myObject = Save(myObject)
You’re adding an extra assignment to the variable, but it’s not really going to cause a performance issue. It’s effectively just doing this C#:
And then calling:
This re-sets the variable reference, but points it to the same object in memory, so there’s little consequence. It’s fairly standard practice for instance methods, though, as it allows for chaining (which you mentioned), ie:
As you’re not chaining, I suspect this was done by somebody who doesn’t properly understand how object references work when calling methods.