is it possible to create and array and populate values?
I’m just getting into unity and c# coming from a flash/AS3 background.
in AS3 it is possible to do the following
var _arr:Array = ["one","two","three"];
trace(_arr[2]);
//three
but i can seem to do this in c#?
string[] arr = string[3];
arr[0]= "one";
arr[1]= "two";
arr[2]= "three";
Debug.Log(arr[2]);
//three
it would be cool if there some syntax that was closer to the the AS3, so that i can pass it to a function without creating it adding the value and so forth!
as3 way just seems like a cleaner way…
//AS3
functionName([1,2,3,4,5]);
//C#
int[] arr = new int[5];
arr[0]= 1;
arr[1]= 2;
arr[2]= 3;
arr[3]= 4;
arr[4]= 5;
FunctionName(arr);
I hope this is possible!!! thanks in advance.
(im not limiting to arrays. Lists, object, dictionarys, or anything with similar syntax will suffice!)
Eric5h5
2
You’d probably be better off using Unityscript since it’s very similar to AS3, in which case you can do
var arr = ["one", "two", "three"];
or
var arr : String[] = ["one", "two", "three"];
But in C# it’s
var arr = new string[3] {"one", "two", "three"};
or
string[] arr = {"one", "two", "three"};