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
VulpesPosted May 9, 2011, 12:36 PM
VulpesPosted May 9, 2011, 6:43 PM
Andrew FensterPosted May 9, 2011, 4:50 PM
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.
Andrew FensterPosted May 9, 2011, 12:24 PM
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));
...
}