次の方法で共有


Set.pack Method

Definition

Serializes the current instance of the Set class.

public:
 cli::array <System::Object ^> ^ pack();
public object[] pack ();
member this.pack : unit -> obj[]
Public Function pack () As Object()

Returns

Object[]

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.

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

Applies to