I just installed Visual Studio 2010 Service pack (proposed on Windows Update), and I can see a new feature on the "intellisense" that means when I write a Function
or Sub
in VB.NET it doesn't auto-complete parameters with ByRef
or ByVal
...
1) Is there anyway that I can configure this option back to how it was before?
2) If I don't specify ByX
, which one is used by default? (it seems like it is always ByRef
)
ByRef = You give your friend your term paper (the original) he marks it up and can return it to you. ByVal = You give him a copy of the term paper and he give you back his changes but you have to put them back in your original yourself.
ByRef (Default)Passing variables by reference is the default and this means that you pass a pointer to the variable and therefore the variable's value can be changed inside the procedure or function.
With a large Byte() array, ByVal is faster than ByRef , but it's also negligible.
C# Passing arguments by default is ByRef instead of ByVal.
It seems that this post covers your question:
http://msmvps.com/blogs/carlosq/archive/2011/03/15/vs-2010-sp1-changing-quot-byval-quot-vb-net-code-editor-experience.aspx
So no, there is no way to get the old behaviour. From now on ByVal
is the default (what it was before) and it won't get added automatically to the method parameters.
In my opinion this is a good decision since it's making VB.NET a bit more consistent with C# and avoids unnecessary "noises"(it's already verbose enough).
Old behaviour:
Private Sub test(ByVal test As String) End Sub
New behaviour
Private Sub test(test As String) End Sub
Tim covered what you asked directly, but something else to keep in mind is that any reference type variable, like a user defined class even if passed by value will allow you to make changes to that instances properties etc that stay. It won't however allow you to change the entire object. Which may be why it seemed to you to be defaulting to by reference
Public Sub (Something As WhateverClass) Something = New WhateverClass 'will result in no changes when outside this method Something.Property1 = "Test" 'will result in an updated property when outside this method End Sub
From MSDN:
The value of a reference type is a pointer to the data elsewhere in memory. This means that when you pass a reference type by value, the procedure code has a pointer to the underlying element's data, even though it cannot access the underlying element itself. For example, if the element is an array variable, the procedure code does not have access to the variable itself, but it can access the array members.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With