Unexpected Results...

Results 1 to 2 of 2

Thread: Unexpected Results...

  1. #1
    Join Date
    Dec 1969

    Default Unexpected Results...

    What I&#039;ve done is created two classes, A and B. Class A contains a public ArrayList as an interface to add instances of class B. For a very simple example of what I want to do:<BR><BR>Class A;<BR>Class B;<BR><BR>B.Text = "apples";<BR>A.aList.Add(B);<BR><BR>B.Text = "oranges";<BR>A.aList.Add(B);<BR><BR>However, what happens when it iterate through the ArrayList(aList) is BOTH of them contain "organges" for their Text property! I have a feeling it&#039;s because I&#039;m only adding a reference to the ArrayList instead of the actual object. This is obviously not the functionality that I want. <BR><BR>TIA!

  2. #2
    Join Date
    Dec 1969

    Default RE: Unexpected Results...

    Hi<BR>I got no experience with .net, but as I see it, You&#039;re right about the reference-thing. aList only holds the reference to B. What you need to do ist creating a new object, somehow like<BR><BR>like B2 = new B();<BR>B2.Text = "organge;-)";<BR>A.aList.add(B2);<BR><BR>Cheers<BR>Didosa

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts