Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Populate list from array

if i have an array. can i populate a generic list from that array:

Foo[] fooList . . . (assume populated array)

// This doesn't seem to work
List<Foo> newList = new List<Foo>(fooList);
like image 578
leora Avatar asked Apr 01 '09 01:04

leora


People also ask

How do you populate an array in Javascript?

Array.fill For example, if we want to set up an array with ten slots and populate it with the string “hello” we'd write some code like this: let filledArray = new Array(10). fill('hello'); This method works great for immutable values like numbers, strings, and booleans.

Can we create a list of array?

ArrayList of arrays can be created just like any other objects using ArrayList constructor.


2 Answers

You could convert the array to a List:

string[] strings = { "hello", "world" };
IList<string> stringList = strings.ToList();
like image 129
Andy White Avatar answered Oct 04 '22 13:10

Andy White


You are looking for List(t).AddRange Method

like image 27
kaivalya Avatar answered Oct 04 '22 13:10

kaivalya