Little beginner's query

  • Thread starter Thread starter stevetanner55
  • Start date Start date
S

stevetanner55

I have successfully created a small application that uses arraylists
of objects. However I have found it quite tiresome , when modifying
one of the objects in the arraylist to have to assign it to a
temporary instance before re-writing it.

something like...

temp_object1 = (object1) object1_arraylist[10]
temp_object1.element = "Something else"
object1_arraylist[10] = temp_object1

because it seems impossible to simply code:

(object1_arraylist[10]).element = "Something else"

Is there a simple way round this? Would pointers help?

Thanks for the tip!

steve tanner
 
I have successfully created a small application that uses arraylists
of objects. However I have found it quite tiresome , when modifying
one of the objects in the arraylist to have to assign it to a
temporary instance before re-writing it.

something like...

temp_object1 = (object1) object1_arraylist[10]
temp_object1.element = "Something else"
object1_arraylist[10] = temp_object1

because it seems impossible to simply code:

(object1_arraylist[10]).element = "Something else"

Is object1 a struct by any chance? If so, it shouldn't really be
mutable to start with - mutable structs are a pain. If it's a class,
you should be able to do:

((object1)object1_arraylist[10]).element = "Something else"
Is there a simple way round this? Would pointers help?

Using a List<T> would help a lot, unless you're still using .NET 1.1.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top