c# - need to search an entire array not just one -


sorry asking question have problem when i'm comparing string string in array search 1 instance of array, example program allows add patients array when used compare string compare last added patient, can me?

this program:

     public class patient     {         public string patientidstring;         public string firstnamestring;         public string lastnamestring;         public string datestring;          public patient()         {             patientidstring = "";             firstnamestring = "";             lastnamestring = "";             datestring = "";         }          public patient(string idvalue, string firstnameval, string lastnameval, string dateval)         {             patientidstring = idvalue;             firstnamestring = firstnameval;             lastnamestring = lastnameval;             datestring = dateval;         }      }       //array     patient[] patientinfo = new patient[10];       private void button1_click(object sender, eventargs e)     {         (int = 0; < patientinfo.length; ++i)         patientinfo[i] = new patient();         try         {             foreach (patient patientinfoindex in patientinfo)              patientinfo[itemcountinteger].patientidstring = textbox1.text;             patientinfo[itemcountinteger].firstnamestring = textbox2.text;             patientinfo[itemcountinteger].lastnamestring = textbox3.text;             patientinfo[itemcountinteger].datestring = datetimepicker1.text;              string names = patientinfo[itemcountinteger].patientidstring + "  " + patientinfo[itemcountinteger].firstnamestring + " " + patientinfo[itemcountinteger].lastnamestring;             listbox1.items.add(names);             itemcountinteger++;             listbox1.selecteditem = names;         }         catch         {             messagebox.show("contacts limited 20. please delete contacts prior adding more.");         }      }       //search button search patients id , display surname in label if patient found  display surname , name     private void button2_click(object sender, eventargs e)     {          int inttest = 0;          (int x = 0; x < patientinfo.length; x++)         {             if (textbox4.text == patientinfo[x].patientidstring)             {                 label6.text = (patientinfo[x].firstnamestring + "  " + patientinfo[x].lastnamestring);                 patientform patientform = new patientform();                 patientform.show();                 patientform.label6.text = (patientinfo[x].patientidstring);                 patientform.label7.text = (patientinfo[x].firstnamestring);                 patientform.label8.text =(patientinfo[x].lastnamestring);                 patientform.datetimepicker1.text = (patientinfo[x].datestring);                 inttest = 1;             }          }          if (inttest == 0)         {             label6.text = ("not found");         }     } 

i'm assuming button1_click function bound add new patient button.

the lines of code

for (int = 0; < patientinfo.length; ++i)     patientinfo[i] = new patient(); 

are clearing out patient data have entered every time add new patient! why ever finding last patient entered when search. you'll want move lines of code elsewhere, such constructor form class.


Comments

Popular posts from this blog

java - WrongTypeOfReturnValue exception thrown when unit testing using mockito -

php - Magento - Deleted Base url key -

android - How to disable Button if EditText is empty ? -