A list-type variable needs to meet the following requirements:
- The List keyword, its element type inside left and right arrow characters, and a unique name
- The new keyword to initialize the list in memory, with the List keyword and element type between arrow characters
- A pair of parentheses capped off by a semicolon
In blueprint form, it reads as follows:
List<elementType> name = new List<elementType>();
List length can always be modified, so there is no need to specify how many elements it will eventually hold when created.
Like arrays, lists can be initialized in the variable declaration by adding element values inside a pair of curly brackets:
List<elementType> name = new List<elementType>() { value1, value2 };
Elements are stored in the order they are added, are zero-indexed, and can be accessed using the subscript operator. Let's start setting up a list of our own to test out the basic functionality this class has on offer.