Tuesday, February 7, 2012

List in X++ / Dynamics AX

List is a type of data structure and collections, it can contain unlimited items, in x++, list can be created of several Types(specified in the Types base enum), the type must be specified on the declaration and it cannot be changed after the initialization.

There are some classes exists to enumerated and iterate the list object. ListIterator object has methods that can insert and deleted items from list,  ListEnumeration cannot modify the list content


    List           myList       = new List(Types::Integer);
    List           myListString = new List(Types::String);
    ListIterator   literator  

    // add the element at the end of the list

    // add the element at the start of the list


    myListString.addEnd ("Second");

    myListString.addStart ("First"); 

    // If you want to insert the data at some specific index, then you need to make use of the listIterator class 

    // Iterator performs a midpoint 

    // insert at current position.

    literator = new ListIterator(myListString);

    while (literator.more())
        // can provide some condition, i.e. if check etc
        if (literator.value() == "First")
            listIterator.insert ("Between first and second");


  1. How do we compare two lists in X++?