c# - How do you change the value of a variable in an instance in windows form -


i have instance of object added list , data displayed in windows form c#. possible change data of instance through windows form?

person joe = new person("sam", "smith", "12.05.1992"); person.add(joe); 

this instance of person added person list.

textbox1.text = person.forename; textbox2.text = person.surname; textbox4.text = person.dateofbirth; 

this how displaying in form through text boxes can input new name , subsequently save changed data.

this thought..

person.forename = textbox1.text; 

but think need after it.

okay, understand person class looks this:

public class person {     public person(string forename, string surname, string dateofbirth)     {         forename = forename;         surname = surname;         dateofbirth = dateofbirth;     }     public string forename { get; set; }     public string surname { get; set; }     public string dateofbirth { get; set; }      public override string tostring()     {         return forename + ";" + surname + ";" + dateofbirth;     } } 

so form should that:

public partial class frmmain : form {     private list<person> persons = new list<person>();      public frmmain()     {         initializecomponent();          person joe = new person("sam", "smith", "12.05.1992");         persons.add(joe);          textbox1.text = persons[0].forename;         textbox2.text = persons[0].surname;         textbox3.text = persons[0].dateofbirth;     }      private void button1_click(object sender, eventargs e)     {         messagebox.show(persons[0].tostring()); // before change         persons[0].forename = textbox1.text;         messagebox.show(persons[0].tostring()); // after change     } } 

but don't quite get, why want list<person> , not 1 person. if have more 1 person in list, how know, 1 display , subsequently change?

ps: advise use datetime type of dateofbirth. you'll in world of trouble if ever want work date of birth...


Comments

Popular posts from this blog

monitor web browser programmatically in Android? -

Shrink a YouTube video to responsive width -

wpf - PdfWriter.GetInstance throws System.NullReferenceException -