Dec 2, 2013

Set In AX

Set contains values of the same type, where value is unique and always sorted on a value

static void testSet(Args _args)
{
Set set = new Set(Types::Integer);
SetIterator sItr;
SetEnumerator sEnum ;

;
set.add(100);
set.add(101);
set.add(102);


info(strFmt("%1",set.toString()));
info(strFmt("%1",set.elements())); //No of elements
info(strFmt("%1",set.in(100))); //To see if a value already is added, use the in method:

set.remove(100);

info(strFmt("%1",set.elements())); //No of elements

// Getting values by using SetEnumerator

sEnum = set.getEnumerator();

while (sEnum.moveNext())
{
info(strFmt("%1",sEnum.current()));
}

// Getting values by using SetIterator

sItr = new SetIterator(set); // initializing set to setIterator
while(sItr.more())
{

info(strFmt("%1",sItr.value()));
sItr.next();
}


}

No comments: