473,386 Members | 1,720 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

ByVal and ByRef

Hi.

Can you tell me what's the difference between ByVal and
ByRef in VB.Net.

I'm asking this 'cause i'm passing an object into a
function ByVal, then I change that object and when the
function terminates the original object is changed.

This kind of output is usual when passing objects ByRef,
right?

Thank's in advance
Goncalo
Nov 18 '05 #1
2 1412
Hi,

For objects (that is, reference types) ByVal means that the function being
called cannot overwrite the *reference* to the object instance which is
actually passed in the parameter variable. But it does not prevent the
callee to alter properties on the instance.

ByRef, on the other hand, enables the callee to overwrite the reference
itself and therefore substitute the original object instance with another
one.

--
Dmitriy Lapshin [C# / .NET MVP]
X-Unity Test Studio
http://x-unity.miik.com.ua/teststudio.aspx
Bring the power of unit testing to VS .NET IDE

"Goncalo" <an*******@discussions.microsoft.com> wrote in message
news:09****************************@phx.gbl...
Hi.

Can you tell me what's the difference between ByVal and
ByRef in VB.Net.

I'm asking this 'cause i'm passing an object into a
function ByVal, then I change that object and when the
function terminates the original object is changed.

This kind of output is usual when passing objects ByRef,
right?

Thank's in advance
Goncalo


Nov 18 '05 #2
Hi,

For objects (that is, reference types) ByVal means that the function being
called cannot overwrite the *reference* to the object instance which is
actually passed in the parameter variable. But it does not prevent the
callee to alter properties on the instance.

ByRef, on the other hand, enables the callee to overwrite the reference
itself and therefore substitute the original object instance with another
one.

--
Dmitriy Lapshin [C# / .NET MVP]
X-Unity Test Studio
http://x-unity.miik.com.ua/teststudio.aspx
Bring the power of unit testing to VS .NET IDE

"Goncalo" <an*******@discussions.microsoft.com> wrote in message
news:09****************************@phx.gbl...
Hi.

Can you tell me what's the difference between ByVal and
ByRef in VB.Net.

I'm asking this 'cause i'm passing an object into a
function ByVal, then I change that object and when the
function terminates the original object is changed.

This kind of output is usual when passing objects ByRef,
right?

Thank's in advance
Goncalo


Nov 18 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
by: Sandy | last post by:
Hello! Help!!!! I have ten zillion books that attempt to describe the difference between ByVal and ByRef and none of them are clear to me. I have gathered that ByVal makes a copy and ByRef...
7
by: Hei | last post by:
Hi, i know the difference of ByRef and ByVal, in case if use byref or byval don't affect the result which one should prefer? (less memory use, better performance ....issue) thx
19
by: Rob Panosh | last post by:
Hello, Ok here is the senerio: ..... Dim myArrayList as New ArrayList(0) me.Test_A( myArrayList )
4
by: Carlos Gomez | last post by:
In VB6 the default for passing variables was ByRef. It was faster and used less memory. Why did MS changed that? Are there any advantages using ByVal over ByRef? (other than ByVal impeding you from...
14
by: Robin Tucker | last post by:
Although I've been working on this project for 8 months now, I'm still not sure of the difference between ByVal and ByRef. As most objects in VB are reference types, passing ByVal I've discovered...
14
by: Niklas | last post by:
Hi What I have learned is that a variable is just a reference when dealing with Objects. Are you supposed to use ByVal or ByRef in functions? They produce the same result or have I missed...
4
by: Warren Sirota | last post by:
Hi, Please let me know if I am interpreting this correctly. I've done a little testing of the difference between passing parameters byVal and byRef, and the results were slightly non-intuitive,...
7
by: barrett bonden | last post by:
Is there any way to pass parameters to a function and simply know there will get there without the silly (C like ) complexity of worring about byval and or perhaps byref ? (Why bother to...
2
by: Witold Iwaniec via .NET 247 | last post by:
It seems that when you pass an object to a function it is always passed by reference even if it is explicitly declared ByVal. Is it the behavior of VB.Net? Here is sample code from sample Asp.Net...
8
by: Boni | last post by:
Dear all, I found out that I don' understand byVal/byRef in VB. There is a simple example: Why in the first test the result is 10,10 where in the second 0,20. Thanks for your help. Boni Module...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.