- Home /
custom function for manipulating builtin array
is there a way to write custom functions for manipulating builtin array of any type?
such as making the following function to accept any type: funtion doublingArraySize(array:){ array=new [array.length*2]; }
intArray:int[]=new int[1]; floatArray:float[]=new float[1]; doublingArraySize(intArray); doublingArraySize(floatArray); //intArray and floatArray can now contains 2elements each
if not possible, is it possible to write reusable code for manipulating builtin array?
Answer by gfr · Nov 04, 2011 at 05:58 PM
You could do such things with C# & generics, e.g.:
void Foo<T>(T[] a) where T : new() {
a[0] = new T();
}
UnityScript/JavaScript however doesn't let you write generic code, only use it.
Your answer
Follow this Question
Related Questions
multidimensional builtin vector3 array? 3 Answers
Help with transfering values from one array to another 1 Answer
Is there a way syntactically to assign all the values of a builtin array in one command? 1 Answer
Checking what slot in a built-in Array my gameobject is in 1 Answer
Slicing error on "builtin" arrays? 2 Answers