structures that can contain members of any X++ type. All the members in the
same list must be of the same type.
The following methods are commonly used on List objects:
• addEnd(anytype) - adds a member to the end of the list.
• addStart(anytype) - adds a member to the start of the list.
• elements() - returns the number of members contained in the list.
• getEnumerator() - returns a ListEnumerator object for this List
object.
• typeId() - returns the Type that the List contains.
The ListEnumerator class allows you to traverse through the elements within a
list. The following methods are commonly used on ListEnumerator objects:
• current() - retrieves the value of the item currently pointed to in the
list.
• moveNext() - moves the enumerator to the next item in the list. List
enumerators start before the first element in the list, so moveNext()
must be called to make it point to the first element in the list.
• reset() - moves the enumerator to the start of the list.
The following example demonstrates how to create a list, then move through it
and extract values from it.
1. Create a new List object, specifying the data type it will contain.
2. Add members to the List object, using the List.addEnd() andList.addStart() methods.
3. Set the ListEnumerator object using the List.getEnumerator()method.
4. Go to the start of the list, using ListEnumerator.reset().
5. Move through the members of the list, usingListEnumerator.moveNext().
6. Pull the value of the current member in the list, usingListEnumerator.current().
1 | List integerList = new List(Types::Integer); |
When the code is executed, the result in the infolog should be as follows:
• First element is 3
• Second element is 1
Best Regards,
Hossein Karimi
*This post is locked for comments