Javascript Array to Generic List

I’m trying to convert a javascript array into a generic list. I’m having trouble with adding items in the definition.
In javascript I have var myarray=New Array(“walk”,“run” etc…);

for generic list I would do

import System.Collections.Generic;
var myarray=new List.(“walk”,“run” etc…);
gives an error that the constructor cannot take String,String.

Is there away to add items in the definition without having to use myarray.Add(“walk”);

Thanks,

1 Answer

1

var aList = new List.([“walk”, “run”, “etc.”]);

Although technically that’s creating a fixed-size array and using the array to initialize the List. Same difference really.

how would I do aList of lists then var aList=new List.<?>(); aList[0]=new list of strings Is there a <type> for lists?

It seems to be deleting my tagstringtag <string>

You might be better off with a 2D array: var array2D = new String[100, 100]; Otherwise, var aList = new List.<List.<String> >(); aList.Add(new List.<String>(["a", "b", "c"])); print (aList[0][0]); Note the space in the > > part; that's actually necessary for some reason.

I've seen some people taking built in arrays and then converting them into javascript arrays and back again if they want to push something or removeAt or use the nice javascript functions. Is that going to be slower than using the .NET List?

You can always convert Lists to built-in arrays and back; there's no reason to use Javascript Array. Mostly you wouldn't need to; Lists are much faster than Javascript Arrays.