Set in D365 F&O - X++ code

 

Set in D365 F&O - X++ code

  • The Set class is used for the storage and retrieval of data from a collection in which the values of the elements contained are unique and serve as the key values according to which the data is automatically ordered.
  • The values may be of any X++ type.
  • All values in the set must have the same type.
  • When a value that is already stored in the set is added, it is ignored and does not increase the number of elements in the set.
  • The values stored in the set can be traversed by using objects of type SetEnumerator. The contents of a set are stored in a way that facilitates efficient look up of the elements.

internal final class SetClassExample
{
    /// <summary>
    /// Class entry point. The system will call this method when a designated menu 
    /// is selected or when execution starts and this class is set as the startup class.
    /// </summary>
    /// <param name = "_args">The specified arguments.</param>
    public static void main(Args _args)
    {
        Set mySet = new  Set(Types::Int64);
        SetEnumerator se;

        mySet.add(12);
        mySet.add(14);
        mySet.add(15);

        se = mySet.getEnumerator();

        while( se.moveNext() ){
            if(se.current() ){
                Info(strFmt("%1 ", se.current()) );
                if(se.current() == 15){
                    Info("Identified the set element");
                }
            }
            else{
                break;
            }
        }

    }

}

Output:


Identified the set element
15
14
12

Comments