Struct.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 Struct class.
public:
virtual cli::array <System::Object ^> ^ pack();
public virtual object[] pack ();
abstract member pack : unit -> obj[]
override this.pack : unit -> obj[]
Public Overridable Function pack () As Object()
Returns
A container that contains the current instance of the Struct class.
Remarks
The pack method is called on each field that holds an object, to yield a (sub) container. The struct may be recreated from the container by using the Struct.create method.
The following example creates a struct with two items in it (name and age), and then adds values to the items. The struct is packed into a container, and this container is then used to create a new struct.
{
container packedStruct;
Struct s1, s = new Struct ("str name; int age");
s.value ("name", "Jane Dow");
s.value ("age", 34);
// Struct is packed into a container
packedStruct = s.pack();
// A new struct is created from the container
s1 = Struct::create(packedStruct);
// Both structs have the same contents
print s.toString();
print s1.toString();
pause;
}