Array.pack Method [AX 2012]
Serializes the current instance of the Array class.
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;
}
Community Additions
ADD
Show: