I have an ArrayList that I enumerate through and want to update a property (Class1 property) within the ArrayList.
arrayList = new ArrayList();
Class1 class1 = new Class1();
...
...
arrayList.Add(class1);
...
...
Class1 temp;
IEnumerator ie = arrayList.GetEnumerator();
while (ie.MoveNext())
{
...
...
...
temp = (Class1)ie.Current;
temp.PropertyA = Convert.ToInt32(objDataReader.GetValue(6));
...
...
...
}
I want arrayList to reflect the value change of PropertyA.
The value is updated in temp, but not in arrayList.
Thanks for your help.
Jason

VulpesRank #55 · 29.2K reputationPosted May 9, 2011, 8:36 AM EDT
Andrew FensterRank #983 · 2K reputationPosted May 9, 2011, 8:24 AM EDT
List myList = new List();
Class1 class1 = new Class1();
...
myList .Add(class1);
...
Class1 temp;
IEnumerator ie = myList.GetEnumerator();
while (ie.MoveNext())
{
...
temp = ie.Current;
temp.PropertyA = Convert.ToInt32(objDataReader.GetValue(6));
...
}
Andrew FensterRank #983 · 2K reputationPosted May 9, 2011, 12:50 PM EDT
I didn't try it, but I was guessing that the reference got lost somehow when you cast the item. I haven't used an ArrayList even once since .Net 2.0 came out with generic collection classes.
VulpesRank #55 · 29.2K reputationPosted May 9, 2011, 2:43 PM EDT