Hi,

How do I return position in an array via a method?

I have this code to retrieve the corresponding phone number from the array when a customer name is entered in the textbox name.

c# Code:
  1. private void txtName_DoubleClick(object sender, EventArgs e)
  2.         {
  3.             bool found = false;
  4.             //Search for a phone number
  5.             //Check and make sure the entered name is in the text file and the name field is not blank
  6.             if (!found && txtName.Text == "")
  7.             {
  8.                 return;
  9.             }
  10.             else
  11.             {
  12.                 cboPhone.Text = RetrievePhone(Name).ToString();
  13.             }
  14.         }
  15.         private int RetrievePhone(string Name)
  16.         {
  17.             //Retrieves the customers phone number from the array
  18.             int counter = 0;
  19.            int Number =  0;
  20.             bool found = false;
  21.             string criteria = txtName.Text;
  22.            
  23.                 while (!found && counter < cPhone.Length)
  24.                 {
  25.                     if (criteria.ToUpper() == cName[counter].ToUpper())
  26.                     {
  27.                         found = true;
  28.                     }
  29.                     else
  30.                     {
  31.                         counter += 1;
  32.                     }
  33.  
  34.                 }
  35.                 //CAUTION: found = true Assigns true to bool variable!
  36.                 if (found == true && txtName.Text != "")
  37.                 {              //NOTE: found == true;      
  38.                     Number = cPhone[counter];
  39.                 }
  40.                 return Number;
  41. }

However, I was told I needed to retrieve the name by entering the phone number and returning the position the match occurred.

Thanks,


Nightwalker