Ejemplo n.º 1
0
        private void Form1_Load(object sender, EventArgs e)
        {
            StreamReader file = new StreamReader("email.txt");

            string line = file.ReadLine();

            /*reads file and splits into array, adds new person object to created list with
             * each iteration. */

            while (line != null)
            {
                string[] x     = line.Split(',');
                string   num   = x[0];
                string   name  = x[1];
                string   email = x[2];

                person = new PersonEntry(num, name, email);
                storage.Add(person);
                //string y = person.getName();

                listBox1.DisplayMember = "Name";                 //displays the property Name in PersonEntry class


                listBox1.Items.Add(person);                 //adds the person object created to the listbox
                line = file.ReadLine();
            }
        }
Ejemplo n.º 2
0
 private void Form1_Load(object sender, EventArgs e)
 {
     try
     {
         string       Person;
         StreamReader inputFile = new StreamReader("C:\\PersonList.txt");
         while (!inputFile.EndOfStream)
         {
             Person = inputFile.ReadLine();
             string[] split  = Person.Split(',');
             var      person = new PersonEntry(split[0], split[1], split[2]);
             People.Add(person);
         }
         inputFile.Close();
         foreach (var PersonEntry in People)
         {
             listBox1.Items.Add(PersonEntry.name);
         }
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.Message);
     }
 }