|
-
May 25th, 2012, 05:08 AM
#3
Re: Object property gets unwnated change?
List(Of T) is a class. In order to create an instance of a class you MUST invoke a constructor using the New keyword. How many times in that code do you do that for the List(Of Single)? Once, therefore there is only one object created. If there's only one List(Of Single) object then obviously every clVessel object must refer to that same object.
Passing a parameter ByVal means that whatever variable you pass is copied and the copy passed to the method. List(Of T) is a class, i.e. a reference type, so the variable contains a reference to an object. When you pass the List(Of Single) to the constructor a copy of that reference is created. As such, you have two references that both refer to the same object, but still only one object. It's always that way for reference type objects. It's exactly the same as assigning one variable to another. The second variable contains a reference to the same object. The only way to create a copy of a reference type object is to actually create a copy, which is always going to involve invoking a constructor with the New keyword again somewhere, either in your code or in the code you call.
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
|