How to modify value in ArrayList?

G

Guest

Given:

ArrayList al=new ArrayList();
int i=1;
al.Add(i);

How can I change the value of al[0] to 2?
(without removing the object and then adding a new one)

This won't work, since int is an value type object:

int k=(int) al[0];
k=2; //(al[0] is not updated since k is a not a referrence to it

Is it possible?

Best Regards
Karl Daggfeldt
 
C

cody

You cannot modify the value without removing and readding it, since as you
already noticed it is a boxed value type.
 
G

Guest

Thanks!
Kalle

cody said:
You cannot modify the value without removing and readding it, since as you
already noticed it is a boxed value type.

--
cody

Freeware Tools, Games and Humour
http://www.deutronium.de.vu || http://www.deutronium.tk
KalleD said:
Given:

ArrayList al=new ArrayList();
int i=1;
al.Add(i);

How can I change the value of al[0] to 2?
(without removing the object and then adding a new one)

This won't work, since int is an value type object:

int k=(int) al[0];
k=2; //(al[0] is not updated since k is a not a referrence to it

Is it possible?

Best Regards
Karl Daggfeldt
 

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

Top