We help IT Professionals succeed at work.

How to pass an array to a procedure

Dovberman
Dovberman asked
on
I need to pass parameters to a procedure.
What is the syntax for passing an array?

// Declare variables
int[] arrDealtCards = new int[2];
        int intHole1 = 5;
        int intHole2 = 7;
        int intFlop1 = 11;
        intFlop2 = 7;

        arrDealtCards[0] = intHole1;
        arrDealtCards[1] = intHole2;
        arrDealtCards[2] = intFlop1;

// Pass variables to the CheckForDup procedure
blnIsDup = CheckForDup(intFlop2, arrDealtCards, 3);  // line 81 generates the error

Error      2      The best overloaded method match for 'PreFlopPractice.CheckForDup(int, int, int)' has some invalid arguments      C:\Users\Admin\Documents\Visual Studio 2008\WebSites\NoLimitBusiness\PreFlopPractice.aspx.cs      81      20      C:\...\NoLimitBusiness\

 private bool CheckForDup(int pintDealtCard, arr[] parrDealtCards, int pintCtr)
    //Returns True if duplicate is found
   
    {
        bool blnIsDup = false;
        // This will loop until intFlop2 = one of the earlier cards
        int intCtr = 0;
        do
        {
            blnIsDup = (pintDealtCard == parrDealtCards[pintCtr]);
            intCtr++;
        }
        while (!blnIsDup);
         
        return blnIsDup;
    }

Thanks,

Comment
Watch Question

High School Computer Science, Computer Applications, Digital Design, and Mathematics Teacher
Top Expert 2009
Commented:
Change:

    private bool CheckForDup(int pintDealtCard, arr[] parrDealtCards, int pintCtr)

To:

    private bool CheckForDup(int pintDealtCard, int[] parrDealtCards, int pintCtr)

*You are passing an array of "int", not an array of "arr".
Most Valuable Expert 2011
Top Expert 2015
Commented:
Change this line:

private bool CheckForDup(int pintDealtCard, arr[] parrDealtCards, int pintCtr)

Open in new window


to this:

private bool CheckForDup(int pintDealtCard, int[] parrDealtCards, int pintCtr)

Open in new window

Author

Commented:
Thank you both for this workable solution.