Advertise with us

More different items in one list

Posted by  marcel ethan
 1304  View(s)
Rate this:

I want to make a list with different items or what I should call it. I mean for example.

public class form1                                                                                                                                            
    public List<string> information = new List<string>();
And I want It to contain information from textboxes with Id, name and phonenumber like this:
private void btnForm_Click(object sender, EventArgs e)
    Form2 Form1= new Form2();
    class Form2a = new Form2();

Then it will be filled with what we can call different customers who have different Id, names and phonenumbers.

Then I want to get the information to another form.

Can someone please help me or give me tips on how?

  1. Re: More different items in one list

    Hi Marcel,

    You should group that information using a class then create and add instances of that class to your list. Below is an example class and some other code you may find helpful.

    public class PersonInfo
         public string Name;
         public string Id;
         public string phoneNumber;
    List<PersonInfo> persons = new List<PersonInfo>();
    // after reading values
    persons.Add(new PersonInfo(txtName.Text, txtId.Text, txtPhoneNumber.Text));
    // if you don't have a constructor like that defined;
    personse.Add(new PersonsInfo {
                        Name = txtName.Text;
                        Id = txtId.Text;
                        PhoneNumber = txtPhoneNumber.Text;
    // get a user by Id
    PersonInfo p = persons.Where(x => x.Id == "that other Id").FirstOrDefault();
    if (p != null)
       // we found our person

      Modified On Apr-04-2018 12:01:49 AM