> I have recently read that passing parameters by value
> provides better performance then passing parameters by
> reference.
Yes, although the difference is fairly slight. It's much more important
that you pick the appropriate semantics, frankly. Don't pass by
reference unless you really mean to.
> Besides that I have also read that VB.NET does not
> actually pass a reference to an object (when using ByRef)
> but what it actually does is copy to value of the object
> back and forth (since the same value has to be used).
>
> Could someone please shed some light on this?
It depends on whether the type in question is a reference type or a
value type, and in VB.NET's case, whether you're passing a property by
reference or a variable by reference. You can't pass a property by
reference in C# - but in VB.NET, passing a property by reference
basically creates a hidden variable which starts off with the current
value of the property, calls the method passing that variable by
reference, then sets the new value of the property to the new value of
the variable. This has somewhat different semantics to passing a
variable by reference, and is generally ugly IMO.
In no case is a copy of the object itself made (assuming the parameter
is a reference type to start with). Could you say where you read about
the copying?

Signature
Jon Skeet - <skeet@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Mark Anthony Spiteri - 15 Feb 2005 08:19 GMT
I have read this at: http://www.dotnetextreme.com/articles/performance.asp
However based on your reply I am assuiming that the author was either
referring to just passing properties or else he mistakinly was using the two
interchangeably.
Going back to the orginal question, could you please clarify what you mean
by "It depends on whether the type in question is a reference type or a
value type" ?
> > I have recently read that passing parameters by value
> > provides better performance then passing parameters by
[quoted text clipped - 24 lines]
> is a reference type to start with). Could you say where you read about
> the copying?
Jon Skeet [C# MVP] - 15 Feb 2005 17:47 GMT
> I have read this at: http://www.dotnetextreme.com/articles/performance.asp
>
> However based on your reply I am assuiming that the author was either
> referring to just passing properties or else he mistakinly was using the two
> interchangeably.
Well, his language is pretty vague - it certainly *looks* to me like he
doesn't know what he's talking about, I'm afraid.
> Going back to the orginal question, could you please clarify what you mean
> by "It depends on whether the type in question is a reference type or a
> value type" ?
Well, the exact cost of passing a parameter depends on its size. For a
reference type, passing by value only requires copying the reference
itself, which is 4 bytes (on a 32-bit CLR). For a value type, all the
data in the value needs to be copied. When a value type is passed by
reference, however, only the address of that value is passed - there's
an indirection cost on access, but the actual passing is relatively
cheap.

Signature
Jon Skeet - <skeet@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too