The List template is a dynamic array implementation.
The Belte public interface for the List template can be found here.
The List template has one template parameter corresponding to the element type.
| Signature | Description |
|---|---|
new List<type T>() |
Creates an empty list. |
new List<type T>(int!) |
Creates a list of a given length where each element is it’s default value. |
new List<type T>(int!, T) |
Creates a list of a given length and fills it with the given value. |
new List<type T>(T[]) |
Creates a list of the same length as the given array and copies the values of the given array into it. |
new List<type T>(List<T>) |
Copies the given list. |
For example, to create an empty list where the elements are of type int:
new List<int>();
| Signature | Description |
|---|---|
void Append(T) |
Adds an element to the end of the list. |
void AppendRange(List<T>) |
Adds a List of elements to the end of the list. |
void Assign(int!, T) |
Assigns a value at a specified index. |
void Clear() |
Removes all elements form the list. |
void Fill(T) |
Fills the entire list with a value. |
const T Index(int!) |
Gets the element at the given index. |
const int Length() |
Gets the number of elements in the list. |
void Pop() |
Removes the last element from the list. |
const List<T> Subset(int!, int!) |
Copies list elements in a sub range to a new list. |
const T[] ToArray() |
Copies all list elements into an array. |
| Signature | Description |
|---|---|
ref T operator[](List<T>, int) |
Gets the value at the given index. |
implicit operator List<T>(T[]) |
Creates a list from an array. |
For example, to index a list:
var myList = new List<int>(10);
var firstElement = myList[0];
Because the index operator returns a reference, you can also assign to the result:
var myList = new List<int>(10);
myList[0] = 5;
The implicit List<T> cast lets you create a list from an array without having
manually write out a constructor call:
List<int> myList = { 1, 2, 3 };