Storing Information In Array

Hi

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?

Many thanks

sounds more like a dictionary, but you’ve not explained the use case in much detail…

For an array that stores a name and a value

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.

Thanks.

Example of scenario:

Item Type: Quantity:
Apple 10
Orange 15

The item types will be predefined, the quantity will be changed accordingly.

apple etc. only ever exists once? I’d definitely go with a dictionary

if you’re after something more like

monday apple 10
tuesday apple 5

etc.

you might want to go with an array/list of structs that hold the 3 bits of information.

Thanks will give this a go.

How efficient is this method (for tablet)?

As the item name will be predefined searching for a particular record should be easy as I can simply access using items[0] etc

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?