- Home /
Question by
tcstarr · Apr 21, 2018 at 01:02 PM ·
c#editoreditor-scriptingobject reference
object field decides when it wants to work,Why does my list clear itself
I have 3 lists
private List<string> variables = new List<string>();
private List<int> choices = new List<int>();
private List<object> contents = new List<object>();
i populate them
public void addCount()
{
count++;
variables.Add("New Item" + variables.Count.ToString());
choices.Add(0);
contents.Add(new myObject(0, 0));
}
my object
public class myObject : object
{
public int aValue;
public int anotherValue
public myObject(int aValueIn, int anotherValueIn)
{
aValue= aValueIn;
anotherValue= anotherValueIn;
}
}
if i call addCount 3 times and call Count variables.Count = 3; choices.Count = 3; contents = 0;
no matter how many times i call addCount contents always returns 0 when i run the game.
Comment
Just checked to make sure and that is definitely not the behavior you will get when recreating this. If you copied that verbatim, then you are missing a ;
on your myObject
class.
What is the point of making
myObject
inhertiing fromobject
?Why do you create a list of
object
while you putmyObject
instances?