Some noobish questions about lists
Hey folks, I have multiple questions about lists. I didn't even know what to search on google to understand this so I came here.
i know how to define a list in unity, but what is this [10] supposed to mean here?
public List (GameObject) [ ] List= new List(GameObject)[10];
Also in this code:
List[1].Clear ();
why this [1] is writtern, shouldn't it be just List.Clear(); ?
At last in this loop
for (int i = 0; i < List1[0].Count; i++) { List2[1].Add (List1 [0] [i]);
}
I know he is adding the element i but what is the [0] doing here. I am having a quite problem trying to understand what these extra index are doing here. Hope you guys help me :)
Answer by Gilead7 · Aug 15, 2017 at 05:10 PM
Think of a list as a flexible array. You use [] to define an array and add a number inside to tell you how many spots to set aside in memory. With a list, you may not know how many elements you need. So you define a list with public List NameofList= New List(); I've taken to using the word list in my variable so I know its a list and don't get confused about it later. Then you can add and loop to your heart's content. You can also call a pre-made function to create the list like NameofList= SingletonInstance.CallfunctionToMakeList(); That works well if it's say a database call in another script.
To help you understand them, I recommend this tutorial by Jonathan Weinberger link text
Hope this help you!
Your answer

Follow this Question
Related Questions
Timer wont work 0 Answers
Getting weird error message!?!?!? 1 Answer
How do I find the direction I'm going for my blend tree? 0 Answers
Make enemy patrol without Nav Points? 0 Answers