- Home /
A List of Lists
Im currently working on a inventory system and i want a list of list for the items. Currently i have
public List<int> itemID = new List<int>();
public List<string> itemName = new List<string>();
public List<int> itemWeight = new List<int>();
But i want itemID to be a list of lists with itemName and itemWeight in it.
Answer by Casper 1 · Apr 23, 2011 at 02:26 PM
The easiest way to do this would to have a class or a struct to contain the itemID, itemName and itemWeight: (Im not sure if mono has get/set properties)
public class Item { public int ID { get; set; }
public int Name { get; set; }
public int Weight { get; set; }
}
Then you have one list of items:
public List<Item> items = new List<Item>();
How do i do to add a item to the list then? I have a script so when you press E you pick up the item, but how do i get that script that's attached to the item.
Well List has a Add method you can use: items.Add(new Item(1, "$$anonymous$$y name", 10))
Just make sure you create a constructor for your class (Item) that accepts the 3 parameters
Your answer
Follow this Question
Related Questions
A node in a childnode? 1 Answer
How can you do calculations on two lists? 1 Answer
How to alphabetically sort your List? 2 Answers
List of bools assigned to each Gameobject in List/Array 0 Answers
wave list into list or( list into array) 3 Answers