Array.pack Method
Definition
Important
Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
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
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;
}