Search through blog..

Sunday, December 1, 2013

What are Containers in AX 2012?

In X++, container is one of the primitive (value) types. A container can contain an ordered sequence of primitive values or other containers.

A container can be used as one of the column types that you can select when you add a new column to a table in AOT. Thereby, it can be stored in the database.
Container is not a class. Containers can be said to be similar to an arary or List/stack classes. But with Containers you can never change size or content of an existing container.

Another interesting thing about containers is that they are immutable. Even though few X++ statements in the System code appear to modify a container, they are actually internally building a new container and copying values as necessary. Even an assignment of a container to another container variable creates a new copy of the container. Because of all this, usage of containers are said to have performance implications.


The X++ function conPeek returns an anytype type. The flexibility of anytype makes container a good way to store values of different types together. This makes it easier to read the values from a container when you do not know what type each value is. An anytype can be assigned to any X++ value type, as long as the value can be converted.

Quick summary:
A container is best suited for processes that do not involve excessive modification to the size or contents of the container.
A container is helpful when you must pass a variety of value types between the client and server tiers.
A container is a poor choice when you intend to repeatedly add to a list in a loop.

No comments: