CryptoJones icon

ByRef_ByValue_Example

CryptoJones | PRO | 12/18/15 07:04:12 PM UTC | 0 ⭐ | 543 👁️ | Never ⏰ | []
VB.NET |

900 B

|

None

|

0 👍

/

0 👎

    Protected Function modifyStuff(ByVal a, ByRef b)
        'notice we'll do stuff with a here, but it won't change in the original function
        a = 5
 
        'now notice here we'll do something to b, and it will show afterwards
        'this isn't generally a good practice, although it can be used
        'but, it's really easy in large programs to get lost on what is getting manipulated where
        'if you need to do something to b, do it here, return b and do b = modifyStuff() in your original function
        b = 5
    End Function
 
 
    Dim connStr = ""
 
    Protected Sub Page_Load(sender As Object, e As EventArgs) Handles Me.Load
 
 
        Dim a = 0.0
        Dim b = 0.0
 
        Response.Write("a before function = " & a & " b before function = " & b)
        modifyStuff(a, b)
        Response.Write("a after function = " & a & " b after function = " & b)
 
    End Sub

Comments

  •  icon
    01/01/70 12:00:00 AM UTC
    Plain Text |

    0 B

    |

    👍

    /

    👎