Store Reference to a Value Type

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • nsphelt
    New Member
    • Jan 2008
    • 4

    Store Reference to a Value Type

    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?
    Last edited by debasisdas; Jan 17 '08, 04:45 AM. Reason: added code tags
  • debasisdas
    Recognized Expert Expert
    • Dec 2006
    • 8119

    #2
    Question moved to .NET forum.

    Comment

    Working...