How to create a list of names with a quantity value?

How to create a list of names with a quantity value that can be added and removed in this case using the names of gameObjects that enter or exit a specific space?

For example a list of students entering and exiting a room, or the names and quantities of items entered into a bag/inventory.

Now iv looked at arrays, list, and dictionary. But I’m still not sure which to use and how to really use them. I know that Arrays are too limited, List might not be enough, and Dictionary might be too much. The issue is that im just not sure how to use them. I wonder of such a list can be created from scratch instead but hooowww. Like the method Mathf.Clamp which takes in 3 parameters puts them through 2 if statements. Also how do you look into Unity methods to see how the inner workings or is that ‘illegal’? I was able to find the body code of Mathf.Camp once but i dont think it was official document.


Additionally, Im wondering how should I structure it in the first place.

I was thinking should the names just be intergers in which their values can be changed?
int Ashley = 6;
int Sherry = 5;

Or should they be 2 values but associated with each other like a string and int?
string Jill, int 3;
string Claire, int 1;

Or maybe vector2s. But I think vectors need to have the same value type?
Vector2 = Ada, 2;

I am not a programmer. Im in the process figuring this out. The hard part is that im using a tablet and cant really test or experiment with anything with in Unity.

There’s a ton of ways to go around it, I suggest getting familiar with C# basic data structures and collections.
Easiest way would probably be with a dictionary, but only if your names can be treated as keys (so there are no 2 same names). If that’s the case then:

Dictionary<string, int> names = new Dictionary<string, int>();
names.Add("Jason", 420);

More about dictionaries here.

Other way would be any other collection like a list, but treating your type as a Tuple or a Pair:

List<Tuple<string, int>> names = new List<Tuple<string,int>>();
names.Add(new Tuple<string, int>("Jason", 420));


Also you can just simply create your own Struct or Class to contain your custom data

class CustomName{
    public string name;
    public int val;

And use it in a collection as a type:

List<CustomName> names = new List<CustomName>();