borderAndreaVB free resources for Visual Basic developersborder

borderAndreaVB Visual Basic and VB.NET source code resources - Copyright © 1999-2007 Andrea Tincaniborder

AndreaVB | Forum | News | Downloads | Register | Help | Member List | Statistics | Search | PM | Profile

Print This Topic
Previous Topic (Javascript date validation ?)Next Topic (What is merge module?) New Topic New Poll Post Reply
AndreaVB Forum : ASP.Net : Value type and reference type ?
Poster Message
tri_inn
Level: Regular User
Registered: 26-08-2002
Posts: 395

icon Value type and reference type ?

all we know the structure is value type and class is reference type.suppose i have declare structure
with three datamember like employee_id type integer,employee_name type string,employee_salary type integer.
and we know the string is reference type so please tell me what will actually happen when structure will
have one or two reference type data member.

13-08-2004 at 03:28 PM
View Profile Send Email to User Show All Posts | Quote Reply
zimcoder
Level: VB Lord


Registered: 27-10-2003
Posts: 225
icon Re: Value type and reference type ?

When you pass a value type to a method/function a copies of the values are actually passed. When you pass a reference type only the address of the reference type is passed, this means that the original values are made available to the calling function.

In this case the structure still holds a reference to the string object, so a copy of the address is passed to the calling function and the original string object is made available for manipulation.

____________________________
BrainBench ADO.NET and ASP.NET Certified Developer

18-08-2004 at 09:58 AM
View Profile Send Email to User Show All Posts | Quote Reply
Chris_871
Level: Master


Registered: 30-11-2002
Posts: 106
icon Re: Value type and reference type ?

Hi

Can you please give any code example for ByVal and Byref.

by

Chris

18-11-2004 at 12:39 PM
View Profile Send Email to User Show All Posts | Quote Reply
Goran
Level: Moderator

Registered: 16-05-2002
Posts: 1681
icon Re: Value type and reference type ?

Code example.... Lets say you have this code in some subroutine:

Dim x as int16

    x=10
    changevalue x
    msgbox x


private sub changevalue(y as int16)
    y=20
end sub


If you run this code, changing value of y variable will not affect x variable's value, cause copy of argument is passed to procedure (default in VB.NET is byval, which is opposite to VB6, where byref is default). If you add byref in front of y asrgument, then procedure takes the actual address of variable, and any change to y also affects x, so x value will be 20.

____________________________
If you find the answer helpful, please mark this topic as solved.

18-11-2004 at 09:17 PM
View Profile Send Email to User Show All Posts | Quote Reply
AndreaVB Forum : ASP.Net : Value type and reference type ?
Previous Topic (Javascript date validation ?)Next Topic (What is merge module?) New Topic New Poll Post Reply
Surf To:


Not Logged In? Username: Password: Lost your password?
Partners: Download Actual Software | Free Software Download
borderAndreaVB free resources for Visual Basic developersborder

borderAndreaVB Visual Basic and VB.NET source code resources - Copyright © 1999-2007 Andrea Tincaniborder