- Home /
Unity 5 array.Add
Hello guys, it seems that this method does not anymore. Could someone tell me how to add an integer to the existing array without nothing between [] those?
int[] tablica = new int[]{liczba1,liczba2};
//then i want to add another integer
tablica.Add(liczba3);
// Does not work. I see a message:error CS1061: Type `int[]' does not contain a definition //for `Add' and no extension method `Add' of type `int[]' could be found (are you missing a //using directive or an assembly reference?)
Thank you for any reply.
I'm not familiar with this extension. Is it part of Linq?
There's always: https://msdn.microsoft.com/en-us/library/vstudio/bb310854%28v=vs.100%29.aspx
Adding additional elements to an array is not a thing. Any extension method you may have used to achieve this in the past most definitely created a new array behind the scenes which was one element larger, then copied the contents of the original, then added the new element at the end. You could create such an extension yourself.
Answer by gRntaus · Apr 22, 2015 at 06:23 AM
You are using a fixed length array and as a result you are not able to add anything to this without redefining it at a larger size and adding the new item to the end of the array.
You are probably wanting to use a List which has both variable length and access to the Add method ass seen on the provided link.
Your answer
Follow this Question
Related Questions
Firebase - Unity Add/Push on Database 2 Answers
Need help with array script 1 Answer
Issue with Lerp and rigidbody in Unity5 0 Answers
Add custom declared variables in a Array 1 Answer
Inventory array add error 1 Answer