private void PopulatePhonesList(Contact newContact) { bool isNoMorePhones = false; do { Phone newPhone = new Phone(); string userInput; Console.Write("Enter Phone description (i.e. work, home, cell etc) or 'X' to move on: "); userInput = Console.ReadLine(); if (userInput.ToUpper() == "X") { isNoMorePhones = true; Console.Clear(); } else { newPhone.PhoneType = userInput; Console.Clear(); Console.Write("Enter {1}'s {0} Phone number: ", newPhone.PhoneType, newContact.FirstName); newPhone.PhoneNumber = Console.ReadLine(); newContact.Phones.Add(newPhone); } } while (!isNoMorePhones); }
public List<Phone> LoadPhoneList(string phoneList) { List<Phone> allPhones = new List<Phone>(); string[] phones = phoneList.Split('%'); foreach (string p in phones) { if (p.Length > 0) //put in to combat last % yielding empty string resulting in "out of range exception" { string[] onePhone = p.Split('^'); Phone aPhone = new Phone(); aPhone.PhoneType = onePhone[0]; aPhone.PhoneNumber = onePhone[1];//null ref using '1', changed to 0 - and back allPhones.Add(aPhone); } } return allPhones; }