private static void ProcessSearchCommands(Phonebook phonebook, string path) { using (var reader = new StreamReader(path)) { var line = reader.ReadLine(); while (line != null) { var command = GetCommandParams(line); if (command.Length == 2) { var nameTown = phonebook.FindByNameAndTownd(command[0], command[1]); foreach (var contact in nameTown) { Console.WriteLine(contact); } } else if (command.Length == 1) { var name = phonebook.FindByName(command[0]); foreach (var contact in name) { Console.WriteLine(contact); } } line = reader.ReadLine(); } } }
private static Phonebook ReadPhonesFromFile(string path) { var phonebook = new Phonebook(); using (var reader = new StreamReader(path)) { var line = reader.ReadLine(); while (line != null) { var currentLine = line.Split(new[] { '|' }, StringSplitOptions.RemoveEmptyEntries); var contact = new Contact(currentLine[0], currentLine[1], currentLine[2]); phonebook.Add(contact); line = reader.ReadLine(); } } return phonebook; }