CryptoJones

ByRef_ByValue_Example

Dec 18th, 2015
389
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VB.NET 0.90 KB | None | 0 0
  1.     Protected Function modifyStuff(ByVal a, ByRef b)
  2.         'notice we'll do stuff with a here, but it won't change in the original function
  3.         a = 5
  4.  
  5.         'now notice here we'll do something to b, and it will show afterwards
  6.         'this isn't generally a good practice, although it can be used
  7.         'but, it's really easy in large programs to get lost on what is getting manipulated where
  8.         'if you need to do something to b, do it here, return b and do b = modifyStuff() in your original function
  9.         b = 5
  10.     End Function
  11.  
  12.  
  13.     Dim connStr = ""
  14.  
  15.     Protected Sub Page_Load(sender As Object, e As EventArgs) Handles Me.Load
  16.  
  17.  
  18.         Dim a = 0.0
  19.         Dim b = 0.0
  20.  
  21.         Response.Write("a before function = " & a & " b before function = " & b)
  22.         modifyStuff(a, b)
  23.         Response.Write("a after function = " & a & " b after function = " & b)
  24.  
  25.     End Sub
Advertisement
Add Comment
Please, Sign In to add comment