Re: Add a Value to an ArrayList



"Andy in S. Jersey" <AndyinSJersey@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in
message news:7DA3C941-CB10-4A85-B706-811C8E23CBAC@xxxxxxxxxxxxxxxx
I would like to add a value to my ArrayList. When I add u to orderedpair
below I get the same data for each. I know why, I am Add ing u. I want
to
add the VALUE of u at the point in the for loop, NOT q.

Does anyone know how to do this?

Perhaps your question would be more clear if you could tell us what you
expect to happen, and what actually happens.

As near as I can tell, you *are* adding "the value of u at the point in the
for loop".

A couple of thoughts:

* If you want to add "u" to a specific position within the "orderedpair"
list, you can use the Insert method instead of Add

* If "u" is not a value type, then what you're adding to the array is a
reference "u", where "u" refers to some instance of some object. If you
don't create a new instance and assign its reference to "u" each time
through the loop, then you're going to wind up with an array that has the
reference to "u" duplicated in each entry, and of course using that
reference will result in getting the same data regardless of which entry in
the array you look at.

Whether either of the above are applicable to your question I don't know.
The question is too vague. If those thoughts don't help, try restating the
question as I suggested above.

Pete


.



Relevant Pages

  • Re: Removing entry from @rray
    ... entry from an @rray. ... and places each line into the array. ... Redefining the @array element inside to loop ... I would also like to ask about terminating a loop ... ...
    (comp.lang.perl.misc)
  • Re: arrays of arrays question
    ... > in ONE array. ... storing a reference to @row in the @rows array. ... in @row when the loop exits. ... and does not go out of scope. ...
    (comp.lang.perl.misc)
  • Re: Removing entry from @rray
    ... For some time I have been using two different method for removing an entry ... and places each line into the array. ... Redefining the @array element inside to loop ...
    (comp.lang.perl.misc)
  • Re: How is this collection called?
    ... you get a possible reference loop when you add the set to itself. ... If you have an array a of references, and add a reference to the array a ... get in trouble - the data structure's graph would have loops, ...
    (comp.theory)
  • Indexing a control
    ... In VB6 I could form an array of labels and reference them by index number. ... I'd like to use a for loop ...
    (microsoft.public.dotnet.languages.csharp)