private static void Main(string[] args) { PhoneBook phoneBook = new PhoneBook(); Console.WriteLine("Search and name for search the phonebook entries"); Console.WriteLine("Exit to terminate the programm"); string input = Console.ReadLine(); while (!String.IsNullOrWhiteSpace(input)) { string[] subscriber = input.Split('-'); string name = subscriber[0]; string number = subscriber[1]; phoneBook.AddSubscribe(name, number); input = Console.ReadLine(); if (input == "search") { while (true) { input = Console.ReadLine(); if (input == "exit") { Environment.Exit(0); } phoneBook.FindSubscriber(input); } } } }
static void Main(string[] args) { List<PhoneEntry> phoneEntries = GetPhones(); PhoneBook phoneBook = new PhoneBook(phoneEntries); List<string> commands = GetCommands(); ExecuteCommands(commands, phoneBook); }
public void StartMenu(PhoneBook phoneBook) { int ans = 0; while (ans != 7) { Console.WriteLine("Меню\n" + "1. Добавить запись\n" + "2. Удалить запись\n" + "3. Изменить запись\n" + "4. Поиск записи\n" + "5. Вывод на экран\n" + "6. Вывод количества записей\n" + "7. Выход\n"); ans = Convert.ToInt32(Console.ReadLine()); switch (ans) { case 1: phoneBook.AddRecord(); break; case 2: Console.WriteLine("Выберите индекс записи для удаления"); int localAns = Convert.ToInt32(Console.ReadLine()); phoneBook.RemoveRecord(localAns); break; case 3: Console.WriteLine("Выберите индекс записи для изменения"); int localAns2 = Convert.ToInt32(Console.ReadLine()); phoneBook.ChangeRecord(localAns2); break; case 4: Console.WriteLine("Выберите индекс записи для поиска"); int localAns3 = Convert.ToInt32(Console.ReadLine()); phoneBook.FindRecord(localAns3); break; case 5: phoneBook.ShowAll(); break; case 6: phoneBook.ShowCountOfRecords(); break; } } }
private static void ExecuteCommands(List<string> commands, PhoneBook phoneBook) { foreach (var command in commands) { List<PhoneEntry> found = new List<PhoneEntry>(); string[] arguments = command.Split(); if (arguments.Length == 1) { found = phoneBook.Find(arguments[0]); } else if (arguments.Length == 2) { found = phoneBook.Find(arguments[0], arguments[1]); } PrintFoundEntries(found, command); } }
public static void Main() { var phonebook = new PhoneBook(); var info = new string[] { "Samantha Fox | Plovdiv | 0888 12 34 56", "Janko Milev | Varna | 052 23 45 67", "Daniela Ivanova Petrova | Karnobat | 0899 999 888", "Sam Sonite | Sofia | 02 946 946 946", "John Smith | Varna | 02 888 946 946", }; info.ForEach(x => { var groomedArray = x.Split('|').Select(y => y.Trim()).ToArray(); phonebook.Add(new PersonInfo() { Name = groomedArray[0], City = groomedArray[1], PhoneNumber = groomedArray[2] }); }); var queries = new string[][] { new string[] { "Samantha" }, new string[] { "Sam Sonite" }, new string[] { "John Smith", "Varna" } }; queries.ForEach(x => { if (x.Length == 1) { phonebook.Find(x[0]).StringJoin().Print(); } else { phonebook.Find(x[0], x[1]).StringJoin().Print(); } }); }
static void Main(string[] args) { PhoneBook phonebook = new PhoneBook(); ConsoleHandler consoleHandler = new ConsoleHandler(); FileHandler fileHandler = new FileHandler(); phonebook.addContact(fileHandler.readContactsFromJson());//reading from file for intial. int choice; choice = consoleHandler.selectFromMenu();; // shows the menu and returns the user's choice while (choice != 5) { CallSwitch(); choice = consoleHandler.selectFromMenu(); //updation in while loop } void CallSwitch() { switch (choice) { case 1: phonebook.addContact(consoleHandler.getContactToCreate()); break; case 2: consoleHandler.showContacts(phonebook.getContacts()); break; case 3: phonebook.deleteContact(consoleHandler.getName()); break; case 4: consoleHandler.showContacts(phonebook.getContacts(), phonebook.findContact(consoleHandler.getName())); break; case 5: break; default: Console.WriteLine(" You have entered a wrong option, Please Try again"); break; } } fileHandler.exportAsJson(phonebook.getContacts()); // storing data into file. }
public static void Main() { //var sampleText = "This is the TEXT. Text, text, text - THIS TEXT! Is this the text?"; //OccurencesCounter.GetOccurrencesFromText(sampleText).StringJoin().Print(); //var hashy = new HashTable<string, string>(); //var rng = new Random(); //var names = new string[] //{ // "gosho", "tosho", "ivan", "skumriq", "gencho", "pencho", "penka", "stamat", "pako", // "djodjo", "strahil", "maria", "uruspiq", "ginka", "nikola", "djena", "plamena", "enrike" //}; //names.ForEach(n => //{ // hashy.Add(n, names[rng.Next(0, names.Length)]); //}); //// remove first 10 //names.Take(10).ForEach(x => hashy.Remove(x)); //// print second 10 via indexer //names.Skip(10).ForEach(x => hashy[x].Print()); var phonebook = new PhoneBook(); var info = new string[] { "Mimi Shmatkata | Plovdiv | 0888 12 34 56", "Kireto | Varna | 052 23 45 67", "Daniela Ivanova Petrova | Karnobat | 0899 999 888", "Bat Gancho | Sofia | 02 946 946 946", "Bat Gancho | Pleven | 02 888 946 946", }; info.ForEach(x => { var groomedArray = x.Split('|').Select(y => y.Trim()).ToArray(); phonebook.Add(new PersonInfo() { Name = groomedArray[0], City = groomedArray[1], PhoneNumber = groomedArray[2] }); }); var queries = new[] { new string[] { "Mimi" }, new string[] { "Bat Gancho" }, new string[] { "Bat Gancho", "Pleven" } }; queries.ForEach(x => { if (x.Length == 1) { phonebook.Find(x[0]).StringJoin().Print(); } else { phonebook.Find(x[0], x[1]).StringJoin().Print(); } }); }