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


Example:

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

    // add the element at the end of the list
    myList.addEnd(2); 

    // add the element at the start of the list
    myList.addStart(3); 

    myList.addEnd(7); 

    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");
        }
    } 



2 comments:

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

    ReplyDelete