I have a class like this:
public class myClass
{
public List<myOtherClass> anewlist = new List<myOtherClass>;
public void addToList(myOtherClass tmp)
{
anewList.Add(tmp);
}
}
So I call "addToList" a hundred times, each adding a unique item to the list. I've tested my items to show that before I run the "addToList" method, they are unique. I even put a line in to test "tmp" to make sure it was what I was expecting.
However, when I do this (lets say myClass object is called tmpClass):
int i = tmpClass.anewList.Count();
for (int j = 0; j<i; j++)
{
//write out each member of the list based on index j...
}
I get the same exact item, and it's the last one that was written into my list. It's as if when I add, I'm overwriting the entire list with the last item I've added.
Help? This makes no sense. I've also tried List.Insert, where I'm always inserting at the end or at index 0. Still no dice. Yes, I'm doubly source my indexing is correct and when I do my test I'm indexing through each of the elements.
:)
UPDATE: Okay, I tried this and still had the same problem:
foreach(myOtherClass tmpC in tmpClass.anewList)
{
Console.WriteLine(tmpC.theStringInMyClass.ToString());
}
and still for each of the 100 items, I got the same string output... I'm sure I'm doing something completely stupid, but I don't know what yet. I'm still 100% sure that the right string is getting passed in to begin with.
-Adeena