Hi
What is difference between Value types and Reference types in VB.NET or C# (Value types VS Reference types?
Thank's Advance..........
Loading
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
Prasant JinagaRank #2,383 · 594 reputationPosted Dec 21, 2011, 8:46 PM EST
value type:
Alten Chingumbra119 reputationPosted Dec 21, 2011, 8:49 PM EST
Satyapriya NayakRank #47 · 31.5K reputationPosted Dec 21, 2011, 9:40 PM EST
ByVal:- means passing a copy of a variable to your Subroutine. You can make changes to the copy and the original will not be altered.
ByRef:- means that you are not handing over a copy of the original variable but pointing to the original variable.Here original value will be changed.
Example:-
Dim x, y As Integer
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
x = 20
y = 30
MsgBox("original value=" & x & " , " & y)
change1(x)
change2(y)
MsgBox("changed value=" & x & " , " & y)
End Sub
Sub change1(ByVal x As Integer)
x = x + 10
End Sub
Sub change2(ByRef y As Integer)
y = y + 10
End Sub
Result
original value= 20,30
changed value= 20,40
Thanks
Alten Chingumbra119 reputationPosted Dec 21, 2011, 11:19 PM EST
Thank U
Posted Dec 22, 2011, 7:15 PM EST