473,386 Members | 1,679 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

How to modify value in ArrayList?

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
Nov 16 '05 #1
2 10919
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" <Ka****@discussions.microsoft.com> schrieb im Newsbeitrag
news:43**********************************@microsof t.com...
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

Nov 16 '05 #2
Thanks!
Kalle

"cody" wrote:
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" <Ka****@discussions.microsoft.com> schrieb im Newsbeitrag
news:43**********************************@microsof t.com...
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


Nov 16 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Maileen | last post by:
Hi, I've asked yesterday if someone already modify data into XML file using VB.NET. In fact, my XML file is like that. .... <DB> <DB_Loc>
6
by: MLH | last post by:
Using A97. Want to examine 17-char VIN entered by user. VIN codes are alphanumeric and do not contain Oh's to prevent the confusion that could result if zeros were misread as O's or o's. So, if...
1
by: Priya | last post by:
Hi, I'm using a repeater control. I'm binding data to repeater dynamically. I need to modify the value of a label at runtime. I modified the text in the ItemDataBound event. But while displaying...
5
by: Alberto | last post by:
I need to modify a value in the app.config file with this code: System.Configuration.Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None); string key =...
1
by: shukyh | last post by:
Hi All i have a XML file with 12 element named "device", and attribute named "project". i wanted to change only the value of one attribute. i tried: XmlNodeList nList =...
6
by: fniles | last post by:
I am using VB.NET 2003 and a socket control to receive and sending data to clients. As I receive data in 1 thread, I put it into an arraylist, and then I remove the data from arraylist and send it...
1
by: Joey | last post by:
Is this possible? I have an app where we are using forms authentication and are allow editing/changing of security role names. Since I have set permissions with <locationtags in web.config (i.e....
6
by: Slickuser | last post by:
Hi, I am picking up C#.net and I'm trying to add many values to one single key at different time in a loop. If the key already exist, append new value to previous? I'm not sure how to do that...
1
by: =?Utf-8?B?SkI=?= | last post by:
Hello My pgm1 (User Interface Level) passes an empty ArrayList to pgm2 (Business Logic Level). pgm2 then calls pgm3 (Data Access Level) to populate the ArrayList. Question1: When pgm2 gets...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.