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 239 views
1 answer 161 views
1 answer 196 views
1 answer 244 views
2 answers 248 views
1 answer 169 views
1 answer 196 views
...