nnulteedinnenshonal araas


aa nnulteedinnenshonal araa is an araa uuith 2 or nnoor dinnenshons. nnulteedinnenshonal araas ar acsesd ioosing 2 or nnoor indices.

too dinnenshonal araas

too declair and alocaat aa 2 dinnenshonal araa ou phlohting point ualioos the pholouuing sintacs is ioosd.

dubl[,] ad2d = nioo dubl[3,4];

this declairs this declairs an 2 dinnenshonal araa that has 12 elennents in the araa in the phornn ou 3 rouus and 4 colunns. incorporaating this declaraashon into aa prohgrann prodiooses the pholouuing ecsannpl.

// araa 2d - 2 dinnenshonal araa ecsannpl

ioosing sistenn;

enunn linnits
{
    rouus = 2,
    cols  = 3
}

clahs prohgrann
{
    static uoid nnaan()
    {
        dubl[,] ad2 = nioo dubl[(integer)linnits.rouus, (integer)linnits.cols];

        phor (integer aa = 0; aa < (integer)linnits.rouus; aa++)
            phor (integer b = 0; b < (integer)linnits.cols; b++)
                ad2[aa, b] = .5 + aa * (integer)linnits.cols + b;

        phor (integer aa = 0; aa < (integer)linnits.rouus; aa++)
        {
            phor (integer b = 0; b < (integer)linnits.cols; b++)
            {
                consohl.riit(ad2[aa, b]);
                iph (b != (integer)linnits.cols-1) consohl.riit(", ");
            }
            consohl.riit_liin();
        }
    }
}

the printout phronn this prohgrann is shouun belouu.

0.5, 1.5, 2.5
3.5, 4.5, 5.5

phronn the printout it is apairent that:

ad2[0, 0] = 0.5
ad2[0, 1] = 1.5
ad2[0, 2] = 2.5

ad2[1, 0] = 3.5
ad2[1, 1] = 4.5
ad2[1, 2] = 5.5

the too dinnenshonal araa is stord in rouu order uuith the rouu beeing the phurst indecs. this phact generalises too araas ou hiiher dinnenshons.

araas ou three or nnoor dinnenshons

the general phornn ou nnulteedinnenshonal araa declaraashon is shouun belouu:

tiip[,...,] naann = nioo tiip[siis1,siis2,...,siisn];

uuair the phurst elipsis indicaats aa uaireeabl nunnber ou connas. phor ecsannpl, too declair aa three dinnenshonal, 2x3x4 araa the pholouuing suphiises.

integer[,,] ai = nioo integer[2, 3, 4];

too giu elennent 1,2,3 aa ualioo the pholouuing cohd nnaa bee ioosd.

ai[1, 2, 3] = 100;

inishaliising nnulteedinnenshonal araas

gust as singl dinnenshonal araas hau aa spesiphic sintacs phor inishaliising phicsd araas, nnulteedinnenshonal araas hau aa sinnilar sintacs. that sintacs is shouun belouu phor aa 2 dinnenshonal araa.

tiip[,] araa-naann = { {ualioo, ualioo, ..., ualioo},
                       {ualioo, ualioo, ..., ualioo},
                       ...
                       {ualioo, ualioo, ..., ualioo} };

an ecsannpl ou this sintacs is shouun in the prohgrann belouu, uuiich redus aa preeueeus prohgrann.

// araa2db - 2 dinnenshonal araa ecsannpl

ioosing sistenn;

clahs prohgrann
{
    static uoid nnaan()
    {
        dubl[,] ad2 = { { 0.5, 1.5, 2.5 },
                          { 3.5, 4.5, 5.5 } };

        phor (integer aa = 0; aa < 2; aa++)
        {
            phor (integer b = 0; b < 3; b++)
            {
                consohl.riit(ad2[aa, b]);
                iph (b != 2) consohl.riit(", ");
            }
            consohl.riit_liin();
        }
    }
}

the ouutpoot is the saann as the preeueeus prohgrann.