.NET

Reply
Valued Mentor
jeff
Posts: 331
Registered: ‎05-12-2009
Message 11 of 13 (111 Views)

Re: vb.net generic list

12-06-2012 10:26 AM in reply to: _gile

Your problem is your adding a shared (static) field of a class however many times.

 

So a shared or static variable for a reference type like in your code points to the same memory location(it actually might get moved around some for optimization), but that variable will always point to same object., and you are just changing the properties of the same object.

 

A variable is just a way in your source code for a name to point to a memory slot.

 

 

A couple of points

 

Reference types by default are passed by value contrary to what you read in books, etc...

 

A value type point to the memory slots that actually that contain the data..

 

A variable for a reference type points to a memory slot that holds only 2 things.

1. Null

2. The address in memory where the object data is stored.

 

 

Dim a as New Class

That just creates a Class object then the varaible 'a' points to a memory slot which contains the address to the object.

Dim b as Class = a

Now b is a different memory slot but is assigned the value of 'a' which is the address of same object.

a.Property = 3

b.Property = 4

All that is happening is when you assign the property using a or b is they are told to modify the property of the object located at the same address.

 

Anything you change with a or b they are going to the same place to update the data.

That is one reason people say reference types are passed by ref.

 

You can assign a = null but b still holds the address to the object.

or

Dim c as new Class

b = c

now b and c hold the address that points to the same object and 'a' value is the address of first object created

 

Now if you pass a reference type by byref you are associating the argument with the same memory slot.

So they both will modify the same object but they both go to the smae memory slot to get that address.

So setting one to null  then both will be null

 

Strings are just a an array of chars and are actully a reference type but are imuttable so they act like a value type.

 

I got a boss on top of me wanting to get a project out and typed this very quickly so probaly not very clear but I was actully planning on doing a post about this topic that will explain it much better with code and pics and go over so other fundamentals that would help expalin it, but boss man is about to come back in check on progress so will give a much better explanation in the next couple of days

 

 

You can also find your answers @ TheSwamp
Valued Mentor
jeff
Posts: 331
Registered: ‎05-12-2009
Message 12 of 13 (105 Views)

Re: vb.net generic list

12-06-2012 11:00 AM in reply to: jeff

The first part was incorrect your not changing the object your changing address it holds which points to a different object.

 

So a shared or static variable for a reference type like in your code points to the same memory location(it actually might get moved around some for optimization), but that variable will always points to the same memory location., and you are just changing the addresss it points to.

 

 

 

You can also find your answers @ TheSwamp
Mentor
khoa.ho
Posts: 219
Registered: ‎09-15-2011
Message 13 of 13 (99 Views)

Re: vb.net generic list

12-06-2012 11:19 AM in reply to: jeff

>>I got a boss on top of me wanting to get a project out and typed this very quickly so probaly not very clear but I was actully planning on doing a post about this topic that will explain it much better with code and pics and go over so other fundamentals that would help expalin it, but boss man is about to come back in check on progress so will give a much better explanation in the next couple of days<<

 

Probably we would NOT let the boss man and colleagues to know that we are playing around with this forum during working hours. :smileyhappy:

 

Post to the Community

Have questions about Autodesk products? Ask the community.

New Post
Need installation help?

Start with some of our most frequented solutions or visit the Installation and Licensing Forum to get help installing your software.