I am trying to set up an array to store information relating to a particular item.
If I wish to store information on a particular item that contains both a string and integer, how would I go about doing this?
For example if I wish to create a table for fruits with quantity sold, would I use a multidimensional array and select string as type and convert the string to integer when required?
public class ItemInformation {
public string name;
public int value;
}
public class YourOtherClass : MonoBehaviour {
private ItemInformation[] items = new ItemInformation[5];
private void DoSomethingMethod() {
items[X].name = "string";
items[X].value = 42;
//or
for (int i = 0; i < items.Length; i++) {
items[i].name = "string";
items[i].value = 42;
}
}
}
But like @LeftyRighty said, depending on your use case also a Dictonary would work or if you are adding items to something also a List would be ok.
That’s correct apple etc will only appear once.
It’s likely that the column numbers would increase, it may be beneficial in that case to go with array.
The example above, that is an array and not an array list, is that correct?
Edit:
For the scenario described, would a playerpref method be better than using an array method?