How to create an object in a class by passing a token to a constructor?

Viewed 171

What I am attempting to do is to take a .txt file that has multiple lines of people's information (Last name, First name, phone number, email) and display the information into a listbox so that a user could select a name in the listbox and display all of the selected person's information in a second form. The instructions for my assignment say that the next thing I should do is Create your object by passing these tokens to your constructor. (Don’t pass the array but rather each element individually.) I have created a class called PersonEntry that constructs 4 strings containing the 4 pieces of information that's included in the .txt file. Here is where I'm at(the first one is my form1.cs code and the second is my PersonEntry.cs class code) and I don't know what to do next. Any help would be much appreciated!

namespace ChalabiMichaelProgram10
{
    public partial class chalabiMichaelProgram10 : Form
    {
        List<PersonEntry> personsList = new List<PersonEntry>;

        public chalabiMichaelProgram10()
        {
            InitializeComponent();
        }

        private void chalabiMichaelProgram10_Load(object sender, EventArgs e)
        {
            try
            {
                StreamReader inputfile;
                string line;
                int count;

                inputfile = File.OpenText("contacts.txt");

                while (!inputfile.EndOfStream)
                {
                    line = inputfile.ReadLine();
                    char[] delimiters = { ',' };
                    string[] tokens;
                    tokens = line.Split(delimiters);

                    for( count = 0; count < 4; count++)
                    {
                        tokens[count] = tokens[count].Trim();

                    }
                }
            }
        }
    }
}

namespace ChalabiMichaelProgram10
{
    class PersonEntry
    {
        //Constructor.
        public PersonEntry()
        {
            lastName = "";
            firstName   = "";
            phoneNumber = "";
            email       = "";
        }
        public string lastName { get; set; }
        public string firstName { get; set; }
        public string phoneNumber { get; set; }
        public string email { get; set; }
    }
}
0 Answers
Related