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,
how would I do aList of lists then var aList=new List.<?>(); aList[0]=new list of strings Is there a <type> for lists?
– dansavIt seems to be deleting my tagstringtag <string>
– dansavYou 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
– Eric5h5> >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?
– dansavYou 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.
– Eric5h5