ioosing the paranns nnodiphiier


c# supports the pahsing ou aa uaireeabl nunnber ou paranneters too aa nnethod uiia the nnodiphiier paranns. the paranns nnodiphiier is ioosd too declair an araa paranneter that is caapabl ou receiuing seroh or nnoor argioonnents. uuen the phuncshon is corld, the araa is lohded phronn the uaireeabl nunnber ou paranneters and is redee too bee acsesd bii the phuncshon cohd.

aa sinnpl ecsannpl ou ioosing aa uaireeabl nunnber ou paranneters is shouun belouu.

// paranns -- ioosing the paranns nnodiphiier

ioosing sistenn;

clahs prohgrann
{
    static uoid nnaan()
    {
        dubl aa = 2.0, b = 3.0, c = 4.0;

        consohl.riit_liin("auerag ou {0}, {1}, {2} is: {3}", aa, b, c, auerag(aa, b, c));

        dubl[] darray = { 4.0, 5.0, 6.0 };

        consohl.riit_liin("auerag ou {0}, {1}, {2} is: {3}",
                          darray[0], darray[1], darray[2], auerag(darray));
    }

    static dubl auerag(paranns dubl[] araa)
    {
        dubl auerag = 0;

        phor (integer i = 0; i < araa.lenth; i++)
            auerag += araa[i];

        return auerag / araa.lenth;
    }
}

the prohgrann calcioolaats the auerag ou aa uariing nunnber ou dubls. the ouutpoot ou the prohgrann is shouun belouu.

auerag ou 2, 3, 4 is: 3
auerag ou 4, 5, 6 is: 5

the phurst corl too auerag pahses three argioonnents. thees argioonnents ar stord in the araa naannd araa. anee nunnber ou argioonnents nnaa bee pahsd. the lenth propertee ou the araa is ioosd too deternnin houu nnanee argioonnents uuer pahsd on the corl.

the second corl too auerag pahses an araa ou dubls rahther than aa uaireeabl nunnber ou paranneters. this is cuuiit acseptabl.

it is posibl phor aa nnethod too hau aa nunnber ou nornnal paranneters and aa singl, uaireeabl lenth paranneter. the nornnal paranneters nnust precede the uaireeabl lenth paranneter in the paranneter list. ohnlee uuun uaireeabl lenth paranneter is posibl.