Share via


Set.pack Method

Serializes the current instance of the Set class.

Syntax

public container pack()

Run On

Called

Return Value

Type: container
A container that contains the current instance of the Set class.

Remarks

The container created by this method contains 3 elements before the first element from the set:

  • A version number for the container

  • An integer that identifies the data type of the set elements

  • The number of elements in the set

If the keys or the values are objects, the pack method is called on each object to create a subcontainer.

You can create a new set from the resulting container by using the Set::create method.

Examples

The following example creates a set of 10 integers, packs it into a container, and then creates a new set with contents identical to the original one.

{ 
    Set is1, is = new Set (Types::Integer); 
    int i; 
    container packedSet; 
    ; 
    // Create a set containing the first 10 integers. 
    for (i = 1; i <= 10; i++) 
    { 
        is.add(i); 
    } 
  
    // Pack it down in a container... 
    packedSet = is.pack(); 
  
    // ... and restore it 
    is1 = Set::create(packedSet); 
    print is1.toString(); 
    pause; 
}

See Also

Set Class

Set::create Method

Pack-Unpack Design Pattern