A
List is a container of variables of the same type, where the data types
boolean,
number,
float, and
string are supported. In contrary to an array, the number of elements in a list is dynamic.
Silk Performer provides a number of functions to work with lists. A list without initialization has the size 0. Adding elements increases
the list size, removing elements decreases the size.
Note: Lists of lists are not supported.
Example
transaction TAList
var
lstNumber: list of number;
lstBoolean: list of boolean;
lstFloat: list of float;
lstString: list of string init "one", "two", "three";
nrVal: number;
begin
ListAdd(lstNumber, 1); // first element
ListAdd(lstNumber, 2); // second element
ListAdd(lstNumber, 3); // ...
ListAdd(lstNumber, 5); // lstNumber == { 1, 2, 3, 5 }
ListInsert(lstNumber, 4, 4); // lstNumber == { 1, 2, 3, 4, 5 }
ListGetFirst(lstNumber, nrVal); // nrVal == 1
Print("nrVal: " + string(nrVal));
ListPrint(lstNumber);
ListSetAt(lstNumber, 3, 33);
ListRemoveFirst(lstNumber);
ListremoveLast(lstNumber);
Print("**************");
ListPrint(lstNumber);
Print("length of the string-list: " + string(ListGetLength(lstString)));
end TAList;
Output
nrVal: 1
element 1: 1
element 2: 2
element 3: 3
element 4: 4
element 5: 5
**************
element 1: 2
element 2: 33
element 3: 4
length of the string-list: 3