Двумерный массив легко организовывается через одномерный, то есть работа идет на деле с одномерным, а при кодировании имитируются двумерные. Вот соотв. фрагмент из Language reference :
Multiple array indices
From other languages like C++ and java, you may be used to declaring arrays with more than one index, that is to define "arrays of arrays". This is not possible directly in X++. Only one-dimensional arrays are supported. However, it is easy to implement multiple indices by using the scheme described below.
Say you wanted to declare an array with two dimensions, for holding an amount earned by country by dimension. What you want to declare is
real earning[10, 3];
where there are 10 countries and 3 dimensions. This is not possible in Axapta, but you can circumvent the problem by defining an one dimensional array with the number of elements that is the product of the elements in each dimension:
real earnings[10*3];
When you wish to refer to earnings[i,j], you simply write
earnings[(i-1)*3 +j].
You can easily wrap this into a macro:
#localmacro.earningIndex
(%1-1)*3+%2
#endmacro
so you could write
earnings[#earningIndex(i,j)]
The above scheme may easily be extended to any number of dimensions. The element a[i1, i2, ..., ik] can be accesses by computing the offset
(i1 - 1)*d2*d3*..*dk +
(i2 - 1)*d3*d4*...*dk + .... +
(ik-1 -1)*dk +
(ik-1)
into an array containing (d1*d2*...*dk) elements
|