Interview Questions

Tuesday, April 15, 2014

Example of Collections in Axapta

I want to store list of objects in X++. I've read in msdn that arrays and containers cannot store Objects, so the only option is to make a list of Collection. I have written the following code and tried to use Collection = new List(Types::AnyType); and Collection = new List(Types::Classes);but both are not working.
static void TestList(Args _args)
{
    List Collection;
    ListIterator iter;
    anytype iVar, sVar, oVar;

    PlmSizeRange PlmSizeRange;
    ;
    Collection = new List(Types::AnyType);

    iVar = 1;
    sVar = "abc";
    oVar = PlmSizeRange;
    Collection.addEnd(iVar);
    Collection.addEnd(sVar);
    Collection.addEnd(oVar);    

    iter = new ListIterator(Collection);
    while (iter.more())
    {
        info(any2str(iter.value()));
        iter.next();
    }
}

No comments:

Post a Comment