How do you combine two lists of different classes into one?

I have two lists that I want to combine into one. One list has a class of member and one has a class for equipment.

I’d like each member to have their name and their equipment listed.

Tom Dick Harry
knife m-16 p90
pistol revolver Colt 45

Do I need a dictionary for this? I’ve tried a combination class
CombineClass Both = new CombineClass(){MemberList=MemberList, EquipmentList=EquipmentList };

It compiles, but I don’t know how to see how to check the data, like I could with a list.count. I know TUPLE is not supported. I’ve tried Ienumerable, concat, and cast using LINQ
IEnumerable all = MemberList.Cast ().Concat (EquipmentList.Cast ());

Again, I don’t know how to work with it to see if it did what I wanted it to.
Anyone have any solutions? I’m open.
Thanks!

Perhaps with a struct, that has a slot for member and another one for equipment and a list of that struct?

public class CombineClass : MonoBehaviour { public List<Members> MemberList; public List<Equipment> EquipmentList; } Something like this?

At that point how do I add the lists? Add? AddRange(which will only work with an iemumerator), put it into a dictionary or something else?

1 Answer

1

If you want a list of equipment for every member in the list, you can do :

Dictionary<Member, <List<Equipment>> membersData;

The use of Member is that the class or the initial list?

I want to have a prefab that instantiates so it will display the name of the member and each piece of equipment they are using. The members are added separately to a database and displayed, thus list one. Then in another screen, you add equipment and display it, list two. In the end all the data goes into a json file to be loaded in a mobile device. Does that make more sense?