On Oct 16, 9:31 am, "Patrice" <http://www.chez.com/scribe/wrote:
Was afraid of that as I was not sure what caused the confusion.
The thing you'll see most often is :
- a variable stores something
- a value type is a type whose data are stored directly by this variable
- a reference type is a type whose data are stored as a reference (a
pointer) to the actual data
For example an integer will be directly stored in the variable (this is a
value type).
On the other hand an object (whose size can vary much, that have methods
etc...) is actually a reference (a pointer) on the actual data that allows
to implements such a behavior.
I wanted to mention that a variable name is basically itself an alias fora
storage location thinking that it could be what caused this confusion...
Hopefully it will be clearer over time - perhaps not thanks to me, sorry
;-)
--
Patrice
<r...@rediffmail.coma écrit dans le message de news:
1192543802.977106.176...@i13g2000prf.googlegroups. com...
On Oct 16, 7:19 am, "Patrice" <http://www.chez.com/scribe/wrote:
[cut]
Patrice, it has indeed been very nice of you to help me grasp the
topic of reference types. Thanks for the same. However I am extremely
sorry to confess that your answer has further compounded my
confusions.
I guess I need a break, think peacefully about it & come afresh
tomorrow with a fresh mind....so see you tomorrow......
Ron
Hopefully it will be clearer over time - perhaps not thanks to me, sorry :-)
No...no....you still deserve a lot of thanks for trying so much to
help me understand this. It's my dumb brain which is at fault
actually.
Anyway, a new day..with a fresh mind..am starting to understand slowly
& steadily (after all, slow & steady wins the race!)....now for some
questions to ensure myself that I am starting to understand this...
Are all variables, be they value types or reference types, ALWAYS
stored in the stack? For e.g. consider the following code:
--------------------------------------
Class MyInt
Public MyValue As Integer
End Class
Sub Page_Load(..........)
Dim x As New MyInt
Dim y As New MyInt
x.MyValue = 15
y = x
y.MyValue = 30
Response.Write(x.MyValue)
End Sub
--------------------------------------
"MyInt", being a reference type, resides in the heap. "x" is also a
reference type but it is stored in the stack BUT it refers to the
class "MyInt" in the heap? So does that mean all variables,
irrespective of their types, are stored in the stack?
BTW, does "x" refer to the class "MyInt" or to the variable "MyValue"
in the class "MyInt"? For e.g. note the line
x.MyValue = 15
Does this mean the variable "MyValue" (which is in the heap) is
assigned a value of 15 & "x" just refers to the variable
"MyValue" (whose value is now 15 in the heap)?
Also note the line
y = x
The above line means that "x" & "y" point to the same object "MyInt"
but what about
y.MyValue = x.MyValue
Doesn't the above line mean that "x" & "y" point to the same object?
Thanks,
Ron