Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections;
- using System.Collections.Generic;
- namespace HomeWorks
- {
- class Program
- {
- static void Main(string[] args)
- {
- List<string> posts = new List<string>();
- List<string> fullNames = new List<string>();
- string userInput = "";
- while (userInput != "exit")
- {
- Console.Clear();
- Console.WriteLine("1) add - Добавить досье\n2) output_all - Вывести все досье\n" +
- "3) delete - удалить досье\n4) exit - Выход из программы\n");
- Console.Write("Введите команду: ");
- userInput = Console.ReadLine();
- switch (userInput)
- {
- case "add":
- AddDossier(ref posts, ref fullNames);
- break;
- case "output_all":
- OutputAll(posts, fullNames);
- break;
- case "delete":
- OutputAll(posts, fullNames);
- DeleteDossier(posts, fullNames);
- break;
- case "exit":
- Console.Write("Все досье будут удалены!\nНажмите любую клавишу для выхода...");
- break;
- default:
- Console.Write("Такой команды нет!\nНажмите любую клавишу для продолжения...");
- break;
- }
- Console.ReadKey();
- }
- }
- static void AddDossier(ref List<string> posts, ref List<string> fullNames)
- {
- Console.Write("Введите должность: ");
- string userInputPost = Console.ReadLine();
- posts.Add(userInputPost);
- Console.Write("Введите ФИО: ");
- string userInputfullNames = Console.ReadLine();
- fullNames.Add(userInputfullNames);
- Console.Write("Досье успешно добавлено!\nНажмите любую клавишу для продолжения...");
- }
- static void OutputAll(List<string> posts, List<string> fullNames)
- {
- int dossierNumber;
- for (int i = 0; i < posts.Count; i++)
- {
- dossierNumber = i + 1;
- Console.WriteLine($"{dossierNumber}. {posts[i]} - {fullNames[i]}");
- }
- }
- static void DeleteDossier(List<string> posts, List<string> fullNames)
- {
- if (posts.Count > 0)
- {
- int dossierIndex;
- int dossierNumber;
- bool userInputIntCorrect = false;
- while (userInputIntCorrect == false)
- {
- Console.Write("Введите номер досье, для его удаления: ");
- string userInput = Console.ReadLine();
- if (userInputIntCorrect = int.TryParse(userInput, out dossierNumber))
- {
- dossierIndex = dossierNumber - 1;
- if (dossierIndex >= 0 && dossierIndex < posts.Count)
- {
- fullNames.RemoveAt(dossierIndex);
- posts.RemoveAt(dossierIndex);
- Console.Write("Досье успешно удалено!");
- }
- else
- {
- Console.Write("Такого досье нет!");
- }
- }
- else
- {
- Console.WriteLine("Некорректный ввод! Повторите попытку.");
- }
- }
- }
- else
- {
- Console.WriteLine("Не найдено ни одного досье!");
- }
- }
- }
- }
Add Comment
Please, Sign In to add comment