Questions tagged [byval]
66 questions
39
votes
7 answers
Which is faster? ByVal or ByRef?
In VB.NET, which is faster to use for method arguments, ByVal or ByRef?
Also, which consumes more resources at runtime (RAM)?
I read through this question, but the answers are not applicable or specific enough.

Robin Rodricks
- 110,798
- 141
- 398
- 607
34
votes
3 answers
Why is it not necessary to indicate ByVal/ByRef anymore?
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…

Yogurtu
- 2,656
- 3
- 23
- 23
25
votes
3 answers
How to 'do' ByVal in C#
As I understand it, C# passes parameters into methods by reference. In VB.NET, you can specify this with ByVal and ByRef. The default is ByVal.
Is this for compatibility with Visual Basic 6.0, or is it just random? Also, how can I specify what to…

Jouke van der Maas
- 4,117
- 2
- 28
- 35
22
votes
4 answers
ByRef vs ByVal Clarification
I'm just starting on a class to handle client connections to a TCP server. Here is the code I've written thus far:
Imports System.Net.Sockets
Imports System.Net
Public Class Client
Private _Socket As Socket
Public Property Socket As…

Brad
- 159,648
- 54
- 349
- 530
18
votes
10 answers
Best Practice: ByRef or ByVal? in .Net
What are the things to consider when choosing between ByRef and ByVal.
I understand the difference between the two but I don't fully understand if ByRef saves resources or if we even need to worry about that in the .Net environment.
How do you…

ctrlShiftBryan
- 27,092
- 26
- 73
- 78
8
votes
5 answers
Passing string ByVal in VB.NET AND C#
So strings are reference types right? My understanding is a reference to the string in the heap is passed even when you pass the string ByVal to a method.
Sooo.....
String myTestValue =…

Maxim Gershkovich
- 45,951
- 44
- 147
- 243
7
votes
6 answers
VB.NET: If I pass a String ByVal into a function but do not change the string, do I have one or two strings in memory?
I know strings are immutable, so the minute you change a string reference's value .NET makes a brand new string on the heap.
But what if you don't change the value of a string reference; rather, you simply pass it into a function ByVal -- does…

Rob Sobers
- 20,737
- 24
- 82
- 111
4
votes
1 answer
VB.NET array parameter mechanism, byval and byref
As a beginner, my question is if an array is passed byval, what on earth the parameter get? I know that array is kind of reference type.
and my guess is that the array parameter byval (hold the array from the argument) should get the copy of the…

Huang Qinlai
- 65
- 7
4
votes
1 answer
COM Interop Method Signature with ByRef
I have a C# program that calls a COM DLL that has a method called test with two parameters: the first parameter is passed ByVal, the second one is passed ByRef.
This is what the COM DLL does:
Public Sub test(ByVal a As String, ByRef b As String)
…

CRK
- 337
- 2
- 10
4
votes
2 answers
Is really argument passing by value?
I'm reading John Skeet's book "C# in Depth". He said on page 74 that everybody suppose that arguments passing to function by reference, meanwhile it's passing by value and as example he shows this code that must prove StringBuilder in calling code…

andrey.shedko
- 3,128
- 10
- 61
- 121
4
votes
3 answers
ByRef vs ByVal performance when passing strings
Reading Which is faster? ByVal or ByRef? made me wonder whether the comments in there did apply to Strings in terms of performance. Since strings are copied before being passed, isn't it much more efficient (if the callee doesn't need a copy of…

Clément
- 12,299
- 15
- 75
- 115
4
votes
1 answer
Switching Byref to Byval on method calls VB.NET
Switching Byref to Byval on method calls
I have many warnings raised due to:
"Implicit conversion from xxxx to yyyy in copying the value of 'ByRef' parameter zzzz back to the matching argument."
My feeling is that it would be safe to change the…

acheo
- 3,106
- 2
- 32
- 57
3
votes
1 answer
Collection Object - ByRef - ByVal
I am using VBA in Access 2013.
In a regular module there are 2 procedures, RunProc() and PopulateCollection()
When RunProc is executed it calls PopulateCollection where the
argument passed is an Collection instace named MyCol.
PopulateCollection…

Michael
- 87
- 1
- 1
- 8
3
votes
1 answer
Pass values from BackgroundWorker DoWork to BackgroundWorker Completed
How do I pass a value from BackgroundWorker DoWork to BackgroundWorker Completed? Since BackgroundWorker Completed is not called by BackgroundWorker DoWork I am not sure how to do this except declare a public variable. Essentially, I want…

Uriel Katz
- 319
- 1
- 8
- 21
2
votes
3 answers
cache being modified instead of local variable (pass by ref)
I am writing a .net c# application.
I retrieve some data from an xml file, cache the data to the .net cache and return it from my method. I perform some processing on the data and return it another part of my application.
Next call, I read from…

amateur
- 43,371
- 65
- 192
- 320