Is there any way I can store a reference to a value type in a variable?
Example:
[CODE=vbnet] Public Class SomeClass
Private valueRef As Integer
Sub UpdateValue(ByR ef value As Integer)
valueRef = value
' This will update the instance passed in by the caller.
value = 10
' This will not.
valueRef = 20
End Sub
Sub Main()
Dim someInteger As Integer
UpdateValue(som eInteger)
' Prints out 10
Console.WriteLi ne(someInteger. ToString)
End Sub
End Class[/CODE]
The variable 'value' in the UpdateValue method is treated like a reference to the 'someInteger' variable because it is passed in ByRef. How can I make the valueRef variabled act in the same way such that the code would print out 20?
Example:
[CODE=vbnet] Public Class SomeClass
Private valueRef As Integer
Sub UpdateValue(ByR ef value As Integer)
valueRef = value
' This will update the instance passed in by the caller.
value = 10
' This will not.
valueRef = 20
End Sub
Sub Main()
Dim someInteger As Integer
UpdateValue(som eInteger)
' Prints out 10
Console.WriteLi ne(someInteger. ToString)
End Sub
End Class[/CODE]
The variable 'value' in the UpdateValue method is treated like a reference to the 'someInteger' variable because it is passed in ByRef. How can I make the valueRef variabled act in the same way such that the code would print out 20?
Comment