|
-
Oct 11th, 2005, 10:12 PM
#1
Thread Starter
New Member
the new class and object
what's the difference between these codes?
-dim variable as button
-dim variable as new button
-dim variable as button = new button
please describe the "NEW" and how it works , in simple word.
in defenition a variable as object ,
what's the difference between these codes?
-dim variable as object
-dim variable as system.object
Imran Hashmi
www.visionstudio.co.uk
www.seo-professional.co.uk 0044-7969012441
-
Oct 11th, 2005, 10:28 PM
#2
Re: the new class and object
-dim variable as button
declares variable as type button, but the variable is set to nothing, and no members of it can be accessed until its constructor (New) is called, or it is set to an existing instance of a button object (like variable = button1, where button1 already existed)
-dim variable as new button
same as above except New is being called so you can access its members and work with all the properties of this object and it is not Nothing
-dim variable as button = new button
longer way to do above (dim variable as new button)
as for
-dim variable as object
-dim variable as system.object
these are the same exact thing, but if you are working with the visual studio IDE, then system is automatically added as a project level imports in the project properties. This means anything that has system as its root, does not need system. typed before it (similar to the way you don't need to type me. in a form to access its members, but you can)
-
Oct 12th, 2005, 09:08 AM
#3
Re: the new class and object
Another way to look at the first two is that declaring the variable:
Dim btn as button
Simply tells the compiler to set aside enough memory to hold one of these objects. The object isn't actually there. All that is there is enough memory for the object.
Dim btn as New Button
and
Dim btn as button = New Button
Both of these tell the compiler to create the memory to hold the object, but also create the object in the memory. Either way, the variable is only a pointer to the memory where the object resides. Until you create a NEW object to put in the memory, there isn't anything there. The variable points to nothing until an object is created.
My usual boring signature: Nothing
 
-
Oct 12th, 2005, 09:15 AM
#4
Re: the new class and object
sort of like what your signature points to Shaggy
-
Oct 12th, 2005, 11:18 AM
#5
Re: the new class and object
The ultimate 0!
My usual boring signature: Nothing
 
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|