The docs say that push and add do the same thing on the array function
http://unity3d.com/support/documentation/ScriptReference/Array.html
Is that a typo, or is it correct? If it is, why are there two functions?
The docs say that push and add do the same thing on the array function
http://unity3d.com/support/documentation/ScriptReference/Array.html
Is that a typo, or is it correct? If it is, why are there two functions?
It’s correct. They are the same so you can use whichever you’re more used to.
–Eric
The difference between the two is that Push() returns the arrays new length, and Add() returns void.
Where would you use functionality like that?
I can’t think of anywhere I’d want the length value returned on a push command.
How about this:
// Adds numbers 1 - 10 to the array
var arr = new Array();
var i = 1;
while (arr.Push(i++) < 10);
Not a great example perhaps, but the point is that some programmers might find Push()'s return value useful. It certainly doesn’t hurt to have one.