How to add an item to a list compossed of my class?

So I have this class:

public class Item {
    public Vector3 position;
    public string type;
}

And then i have a list that contains items of this class:

[HideInInspector]
public Item[] droppedItems;

But when i try to add an item to droppedItems:

Item log = new Item();
log.position = logObj.transform.position; log.type = "log";
droppedItems.Add(log);

It gives me this error:

Assets\GameLogic.cs(138,22): error CS1061: ‘Item’ does not contain a definition for ‘Add’ and no accessible extension method ‘Add’ accepting a first argument of type ‘Item’ could be found (are you missing a using directive or an assembly reference?)

It doesn’t matter where the item is placed in the list. How can i do this?

The first thing to know is the difference between Arrays and Lists. Long story short, to use arrays you need to know its length beforehand meanwhile Lists can have a variable size.

.Add is the method you use to add a new item to a List. It will append the new item to a new slot at the end of the list.

To add an item to an array you need to have previously defined the size of the array and then assign manually the item to a given index from the array:

public Item[] droppedItems = new Item[5]; 

where 5 is the number of ‘slots’ you want available in the array

Item log = new Item();
log.position = logObj.transform.position; log.type = "log";
droppedItems[0] = log;

0 here is the index where you want to store the new item.

If you want to know more about Arrays and Lists you can head to Unity Learn.