Coffeehouse Post

Single Post Permalink

View Thread: Visual Basic.Net Reference vs Instantiate
  • User profile image

    Expanding on spivonious ...


    Dim Joe as Guy
    'Joe is nothing at this point
    Dim Fred as New Guy
    'Fred is something, a newly initialized Guy (blank name, 0 age, not awesome)
    Joe = Fred
    'Now Joe points to the same thing as Fred
    Joe = GetGuy()
    'Now Joe points to a new instance of Guy (a initialized 42 year old awesome guy named Fred)
    'Fred still points to his original initialized Guy (blank name, 0 age, not awesome)
    Function GetGuy() as Guy
        Dim tempGuy as New Guy
        tempGuy.Name = "Fred"
        tempGuy.Age = 42
        tempGuy.IsAwesome = True
        return tempGuy
    End Function
    Private Class Guy
      'Property syntax shortened for brevity
      Public Property Name() as String
      Public Property Age() as Integer
      Public Property IsAwesome() as Boolean
    End Class