Wednesday, January 2, 2008

ByVal vs ByRef (1)


' *** Wrong: the method doesn't need to modify the pointer

Sub ClearProperties(ByRef u As User)

u.FirstName = Nothing

u.LastName = Nothing

End Sub

' *** Corrent: the object is passed by value

Sub ClearProperties(ByVal u As User)

u.FirstName = Nothing

u.LastName = Nothing

End Sub

' *** Corrent: the method assigns a new object reference

Sub ClearProperties(ByRef u As User)

u = New User

End Sub

blog comments powered by Disqus