- Home /
Question by
FTheCloud · Aug 23, 2011 at 03:43 PM ·
array.netaddingstatic-vars
Add to .net Arrays
How would you add GameObjects to a .Net array?
var Whatever : GameObject[];
The Whatever.Add();
doesn't seem to work with statically typed and in this case I don't want to use dynamically typed.
Comment
Best Answer
Answer by Bunny83 · Aug 23, 2011 at 04:06 PM
Native arrays can't be resized dynamically. They have to be recreated with the new size and you have to copy the old elements into the new array.
Usually you would use a container class for such a task.
Use generic List:
var whatever : List.<GameObject>;
whatever = new List.<GameObject>();
whatever.Add(gameObject);
Your answer
![](https://koobas.hobune.stream/wayback/20220612190716im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
How to add an object to an array? 1 Answer
problem adding element of array 1 Answer
How do I Resize an Array in JS? 1 Answer
Add GameObject to GameObjectArray[] 3 Answers
Generics and Arrays 1 Answer