Coffeehouse Post

Single Post Permalink

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


    The reference created in the first example is indeed a reference, but it's empty. At that point joe is still null. This is useful if you are going to get the actual object from somewhere else and don't need to create a new one. Say, if you had a method that created a Guy object, you would do like so:

    Dim joe as Guy
    joe = GuyMethod()

    which is also the same as:

    dim joe as guy = GuyMethod()

    Really, you don't need to create a reference and instantiate it on different lines.


    Dim joe as New Guy

    is the same as:

    Dim joe as Guy
    joe = new Guy

    If you did both lines like you had in your example:

    Dim Joe as Guy
    Dim Joe as New Guy

    You would get a compiler error because you told it to create two separate variables with the same name.

    EDIT: On the subject of learning, you might check out this search and this search on MSDN. Some of the articles are a bit old, but the principles are sound.

    I think it's funny that when you include the language you want to use, you get a whole bunch of people obviously looking for people to do their homework for them.