แชร์ผ่าน


Array.pack Method

Definition

Serializes the current instance of the Array 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 Array class.

Remarks

The container created by this method contains three elements before the first element from the array:

  • A version number for the container.
  • An integer that identifies the data type of the array elements.
  • The number of elements in the array.

If the values of the array are objects, the pack method is called on each object to yield a subcontainer.

The following example creates an array of integers and adds some values to it. The pack method is used to pack the array into a container, and the container is then used to create a new array.

{ 
    int i; 
    container packedArray; 
    // Create an integer array 
    Array ia = new Array (Types::Integer); 
    Array iacopy; 
    // Write some elements in it 
    for (i = 1; i< 10; i++) 
    { 
        ia.value(i, i*2); 
    } 
    // Pack the array 
    packedArray = ia.pack(); 
    // Unpack the array  
    iacopy = Array::create(packedArray); 
    // Check the values 
    for (i = 1; i< 10; i++) 
    { 
        if (iacopy.value(i) != 2*i) 
        { 
            print "Error!"; 
        } 
    } 
    pause; 
}

Applies to