List of Lists

What would you like to see in CSPro?
Post Reply
slwendo
Posts: 17
Joined: March 11th, 2017, 4:13 pm

List of Lists

Post by slwendo »

eg. list string tinyList1;
list string tinyList2;
list string tinyList3;

list bigList = tinyList1, tinyList2, tinyList3;
justinlakier
Posts: 227
Joined: November 21st, 2022, 4:41 pm

Re: List of Lists

Post by justinlakier »

Hello,

A List is one-dimensional and can hold either numeric or string values. It cannot contain other lists. For this, you may want to use a multidimensional Array to hold your list values. In the example below, the array has 2 dimensions- the first dimension for the number of lists to keep track of, and the second dimension for the length of the lists. A do loop then takes all values from these lists into the array. Arrays in CSPro need constant dimensions, so this assumes that you have determined the number and length of lists ahead of time, and that the length of the lists can be made to match. If this is too rigid for your application, you may want to look into a multidimensional HashMap object instead
array string myArrayOfLists(3, 6);
list string firstList = "1","2","3","4","5","6";
list string secondList = "6","5","4","3","2","1";
list string thirdList = "1","1","1","1","1","1";

do numeric i=1 until i>6
   
myArrayOfLists(1,i) = firstList(i);
    myArrayOfLists(2,i) = secondList(i);
    myArrayOfLists(3,i) = thirdList(i);
enddo;

showarray(myArrayOfLists);
Hope this helps,
Justin
slwendo
Posts: 17
Joined: March 11th, 2017, 4:13 pm

Re: List of Lists

Post by slwendo »

Thanks!
Post Reply