How to use ByVal and ByRef in with variable VB.NET

1 Answer

0 votes
Module Module1

    Sub Main()

        Dim n As Integer = 5

        s(n)
        Console.WriteLine(n)

        s_byval(n)
        Console.WriteLine(n)

        s_byref(n)
        Console.WriteLine(n)

    End Sub

    Sub s(n As Integer) ' ByVal is the default
        n = 111
    End Sub

    Sub s_byval(ByVal n As Integer)
        n = 222
    End Sub

    Sub s_byref(ByRef n As Integer)
        n = 333
    End Sub

End Module

'run:
' 
' 5
' 5
' 333

 



answered Mar 2, 2016 by avibootz

Related questions

1 answer 327 views
1 answer 251 views
1 answer 280 views
1 answer 344 views
2 answers 385 views
1 answer 261 views
1 answer 286 views
...