T
The unProfessional
Hi everyone,
I've been developing .net apps for some time now, but there are still some
things that're unclear in regards to how .Net manages pointers internally.
ArrayList lst = new ArrayList ();
....
lst.Add (new MyClass());
....
MyClass c = (MyClass) lst[0]; // <-- Is this a pointer or a new copy of
the object??
If I then modify a member of the class pointed to by "c", it isn't reflected
in the version that's still stored
in the ArrayList. Why is this? Does .Net make another copy of the object
when I cast it down from the ArrayList? If so, WHY? And if not, why are my
changes not reflected?
It seems to me that allocation should only occur for reference types when
you use the "new" operator... otherwise, you should simply be dealing with
pointers. All value types (native or structures) are always on the stack
(rather than the heap), right? Clarification would be much appreciated.
Thanks in advance
I've been developing .net apps for some time now, but there are still some
things that're unclear in regards to how .Net manages pointers internally.
ArrayList lst = new ArrayList ();
....
lst.Add (new MyClass());
....
MyClass c = (MyClass) lst[0]; // <-- Is this a pointer or a new copy of
the object??
If I then modify a member of the class pointed to by "c", it isn't reflected
in the version that's still stored
in the ArrayList. Why is this? Does .Net make another copy of the object
when I cast it down from the ArrayList? If so, WHY? And if not, why are my
changes not reflected?
It seems to me that allocation should only occur for reference types when
you use the "new" operator... otherwise, you should simply be dealing with
pointers. All value types (native or structures) are always on the stack
(rather than the heap), right? Clarification would be much appreciated.
Thanks in advance