Generic Lists?

Hey guys I have been looking all day for something that can explain a little better how I can do this problem I am having.

I have two Class’s that contains lists that will function as abstract AI variables, And I want to make a generic method to handle something like this:

class AddToList<T>
{
    T _value;
    private List<string> _NameOfEntity = new List<string>();
    private List<int> _AgeOfEntity = new List<int>();
    
    public void AddToList(T t)
    {
        listInt.Add(_value);
    }
}

AddToList<string> addToList = new AddToList<string>{"Name"};
Or
AddToList<int> addToList = new AddToList<int>{18};

That would be able to grab the Int or the string and add it to the correct list. I am trying to understand this better so any help would be greatly appreciated.

So if you have 2 instances of this class and you want them to take in different type each, you would just do

 class AddToList<T>
 {
     private List<T> list = new List<T>();

     public void AddToList(T t)
     {
         list.Add(t);
     }
 }

As such the class doesn’t offer you anything new compared to having 2 Lists of different types, but i guess you’d be building more logic iside the class.

If you want 1 class that takes in string and int and puts them in different lists depending on their type, generics won’t help you much. You’ll just have to overload the AddToList method so you have a version of it for int and string.