Compartir a través de


Struct.pack Method

Definition

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

Object[]

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

Applies to