Is there an equivilent to VB.NET ByVal?

  • Thread starter Thread starter John Galt
  • Start date Start date
J

John Galt

I was looking at a VB.NET program that is passing strings to method calls
using ByVal. I was wondering if this is for a reason and, if so, should a C#
conversion of code samples from VB.NET also use an equivilent rather than
passing strings by reference?
 
The default parameter passing in C# is 'ByVal' as well - it's just there is
no keyword for it. ByVal means that a copy of the *reference* is passed.
Never is a copy of the object passed for reference types.
 
John Galt said:
I was looking at a VB.NET program that is passing strings to method
calls using ByVal. I was wondering if this is for a reason and, if
so, should a C# conversion of code samples from VB.NET also use an
equivilent rather than passing strings by reference?

Everything is passed by value in C# unless you specify otherwise. For
strings, this means the string reference is passed by value, because
string is a reference type.

See http://www.pobox.com/~skeet/csharp/parameters.html for more
information.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top