I am attempting to pass an ArrayList to a class, inside of a foreach loop. Each ArrayList is unique going in, however, after the loop, all ArrayLists have the same values.
I am doing:
foreach(myclass tempClass in myClassArrayList)
{
ArrayList bla = tempClass.GetArrayList();
//play around with bla, get it how it should be for this instance
//at this point bla is unique
tempClass.SetArrayList(bla);
}
//after this foreach, all myclass's in myClassArrayList have the same .GetArrayList() values, yet maintain different hash codes.
myclass.SetArrayList(ArrayList incoming)
{
this.myClassesArrayList = new ArrayList(incoming);
}
-- run this somewhere
ArrayList myClassArrayList = new ArrayList();
myClassArrayList.Add( new myclass() );
myClassArrayList.Add( new myclass() );
foreach(myclass tempClass in myClassArrayList)
{
ArrayList bla = tempClass.GetArrayList();
//play around with bla, get it how it should be for this instance
//at this point bla is unique
tempClass.SetArrayList(bla
}
System.Diagnostics.Debug.W
System.Diagnostics.Debug.W
---
public class myclass
{
private ArrayList myClassesArrayList;
static int iCounter = 0;
public myclass()
{
myClassesArrayList = new ArrayList();
myClassesArrayList.Add( iCounter );
myClassesArrayList.Add( iCounter + 100 );
iCounter++;
}
public void SetArrayList(ArrayList incoming)
{
this.myClassesArrayList = new ArrayList(incoming);
}
public ArrayList GetArrayList()
{
return myClassesArrayList;
}
public override string ToString()
{
return "I am instance " + ((int)myClassesArrayList[0
}
}