can't save values from another class to a list
I'm trying to save int values from my Miners_Manager class in a list then convert them to strings and write them in a folder. But after the foreach my list is always empty.
public Miners_Manager[] items;
public string[] save = new string[100]; // Array of strings
public List<int> itemcount = new List<int>(); // List of values
public int length; // Length of the list
public void createString()
{
int i = 1;
foreach (var item in items)
{
itemcount[i] = item.count; // saving the values in the list - this doesn't work
i += 1;
}
length = itemcount.Count; // calculating length of list
for (i= 2; i <= length; i++)
{
save[i] = itemcount[i].ToString();
}
Comment
Answer by rob5300 · Mar 28, 2017 at 05:59 PM
To add a new object to a list you need to use List.Add(T). Doing that should solve the issue.
Soo you need to:
itemcount.Add(item.count);