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:
private void txtName_DoubleClick(object sender, EventArgs e)
{
bool found = false;
//Search for a phone number
//Check and make sure the entered name is in the text file and the name field is not blank
if (!found && txtName.Text == "")
{
return;
}
else
{
cboPhone.Text = RetrievePhone(Name).ToString();
}
}
private int RetrievePhone(string Name)
{
//Retrieves the customers phone number from the array
int counter = 0;
int Number = 0;
bool found = false;
string criteria = txtName.Text;
while (!found && counter < cPhone.Length)
{
if (criteria.ToUpper() == cName[counter].ToUpper())
{
found = true;
}
else
{
counter += 1;
}
}
//CAUTION: found = true Assigns true to bool variable!
if (found == true && txtName.Text != "")
{ //NOTE: found == true;
Number = cPhone[counter];
}
return Number;
}
However, I was told I needed to retrieve the name by entering the phone number and returning the position the match occurred.
Thanks,
Nightwalker