Specifies that the System.Xml.Serialization.XmlSerializer must serialize a particular class member as an array of XML elements.
See Also: XmlArrayAttribute Members
The System.Xml.Serialization.XmlArrayAttribute belongs to a family of attributes that controls how the System.Xml.Serialization.XmlSerializer serializes or deserializes an object. For a complete list of similar attributes, see Attributes That Control XML Serialization.
You can apply the System.Xml.Serialization.XmlArrayAttribute to a public field or read/write property that returns an array of objects. You can also apply it to collections and fields that return an ArrayList or any field that returns an object that implements the IEnumerable interface.
When you apply the System.Xml.Serialization.XmlArrayAttribute to a class member, the XmlSerializer.Serialize(System.IO.TextWriter, object) method of the System.Xml.Serialization.XmlSerializer class generates a nested sequence of XML elements from that member. An XML schema document (an .xsd file), indicates such an array as a complexType. For example, if the class to be serialized represents a purchase order, you can generate an array of purchased items by applying the System.Xml.Serialization.XmlArrayAttribute to a public field that returns an array of objects that represent order items.
If no attributes are applied to a public field or property that returns an array of complex or primitive type objects, the System.Xml.Serialization.XmlSerializer generates a nested sequence of XML elements by default. To more precisely control what XML elements are generated, apply an System.Xml.Serialization.XmlArrayItemAttribute and an System.Xml.Serialization.XmlArrayAttribute to the field or property. For example, by default, the name of the generated XML element is derived from the member identifier You can change the name of the generated XML element by setting the XmlArrayAttribute.ElementName property.
If you serialize an array that contains items of a specific type and all the classes derived from that type, you must use the System.Xml.Serialization.XmlArrayItemAttribute to declare each of the types.
You can use XmlArray in your code instead of the longer System.Xml.Serialization.XmlArrayAttribute.
For more information about using attributes, see Extending Metadata Using Attributes.