c# - Changing struct to class? -


i want change struct patient class when program don't work(free of errors) want substitute struct patient class patientn, can see button click uses struct patient , want change class , still work. visual studio 10 program:

public partial class form1 : form {     int itemcountinteger; public struct patient {     public string patientidstring;     public string firstnamestring;     public string lastnamestring;   }  public form1() {     initializecomponent(); }  private void form1_load(object sender, eventargs e) {   }   public class patientn {     private int patientid;     public string firstname;     private string lastname;      public patientn()     {         patientid = 0;         firstname = "";         lastname = "";     }      public patientn(int idvalue, string firstnameval, string lastnameval)     {         patientid = idvalue;         firstname = firstnameval;         lastname = lastnameval;     }  }  //array patient[] patientinfo = new patient[10]; //this method used add items array , display listbox private void button1_click(object sender, eventargs e) {     try     {         foreach (patient patientinfoindex in patientinfo)          patientinfo[itemcountinteger].patientidstring = textbox1.text;         patientinfo[itemcountinteger].firstnamestring = textbox2.text;         patientinfo[itemcountinteger].lastnamestring = textbox3.text;          string names = 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.");     }  } 

you should explicitly create class instances. in case

// it's quite enough since patient struct patient[] patientinfo = new patient[10]; 

in case of patientn class should be

// was... patientn[] patientinfo = new patientn[10];  // should add since patientn class (int = 0; < patientinfo.length; ++i)   patientinfo[i] = new patientn(); 

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 ? -