Results 1 to 6 of 6

Thread: little confusing!![resolved]

  1. #1

    Thread Starter
    Sleep mode
    Join Date
    Aug 2002
    Location
    RUH
    Posts
    8,083

    little confusing!![resolved]

    What's the difference between these two lines , they give the same result though.
    VB Code:
    1. dim object as new baseclass
    2. 'and
    3.  
    4. object= new baseclass
    Last edited by Pirate; Dec 4th, 2002 at 05:10 PM.

  2. #2
    Member
    Join Date
    Sep 2002
    Location
    California
    Posts
    52
    The top one declared a new variable then creates an Object in memory, then points the variable to that Object.

    The bottom one simply creates an Object in memory then points a previously created variable to it.

    Dim o As New Object is just short for Dim o As Object = New Object.

  3. #3

    Thread Starter
    Sleep mode
    Join Date
    Aug 2002
    Location
    RUH
    Posts
    8,083
    oh God , I completely got stuck.
    if you'r right ,so why MS duplicates the way it declares variables then???

  4. #4
    Your Ad Here! Edneeis's Avatar
    Join Date
    Feb 2000
    Location
    Moreno Valley, CA (SoCal)
    Posts
    7,339
    What do you mean 'why MS duplicates the way it declares variables?'

    Those are two different things. Lets say you have been working with an object and now you want to reuse the same variable but start a new object well there is not reason to dim or create a new variable to hold the new object just reuse the old one.

    You are thinking of
    Dim o As New BaseClass

    As 1 thing but its not its 2

    the Dim and New commands are seperate commands they are just often used together. Dim creates a new variable. New initializes a new instance of an object.

  5. #5
    Banished Cander's Avatar
    Join Date
    Dec 2000
    Location
    Why do you care?
    Posts
    6,913
    it just a matter of when you want to bond the variable to something

    There are mutiple ways to do this all depending on when and where you want to specify a New or existing object into that variable


    Dim a As Object
    Dim b As New Object

    now say you want a to = b then that is why the line a = New Object is valid becasue you are assigning a to something else wether it is a new object or an existing one..in which case you would say a = b

    if you coldnt do
    a = New Object
    then you also couldnt do
    a = b


    Get it?
    Stack Overflow
    See the features of Visual Studio 2010 and C# 4.0: The 10-4 show on Channel9

  6. #6

    Thread Starter
    Sleep mode
    Join Date
    Aug 2002
    Location
    RUH
    Posts
    8,083
    wow , perfectly integrated in my mind.wyrd maybe couldn't explain that well , so that messed me up!
    thanx a lot Edneeis and Cander

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width