Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- static void Main(string[] args)
- {
- const string AddDossiser = "1";
- const string ShowAllDossiser = "2";
- const string RemoveDossiser = "3";
- const string SearchDossiser = "4";
- const string Exit = "5";
- string[] arrayFullNames = new string[0];
- string[] arrayPositions = new string[0];
- bool isExit = true;
- while (isExit)
- {
- Console.WriteLine("1) Добавить досье \n" +
- "2) Вывести все досье \n" +
- "3) Удалить досье \n" +
- "4) Поиск по фамилии \n" +
- "5) Выход");
- string input = Console.ReadLine();
- switch (input)
- {
- case AddDossiser:
- AddDossier(ref arrayFullNames, ref arrayPositions);
- break;
- case ShowAllDossiser:
- ShowAllDossier(arrayFullNames, arrayPositions);
- break;
- case RemoveDossiser:
- RemoveDossier(ref arrayFullNames, ref arrayPositions);
- break;
- case SearchDossiser:
- SearchDossier(arrayFullNames, arrayPositions);
- break;
- case Exit:
- isExit = false;
- break;
- default:
- Console.WriteLine("Неверный код");
- break;
- }
- Console.WriteLine("");
- }
- }
- private static void AddDossier(ref string[] arrayFullNames, ref string[] arrayPositions)
- {
- Console.WriteLine("Введите ФИО.");
- string fullname = Console.ReadLine();
- Console.WriteLine("Введите Должность");
- string post = Console.ReadLine();
- arrayFullNames = IncreasArray(arrayFullNames, fullname);
- arrayPositions = IncreasArray(arrayPositions, post);
- }
- private static string[] IncreasArray(string[] array, string inputText)
- {
- string[] tempArray = new string[array.Length + 1];
- for (int i = 0; i < array.Length; i++)
- {
- tempArray[i] = array[i];
- }
- tempArray[array.Length] = inputText;
- return tempArray;
- }
- private static void RemoveDossier(ref string[] arrayFullNames, ref string[] arrayPositions)
- {
- Console.WriteLine("Введите индекс досье");
- if (int.TryParse(Console.ReadLine(), out int result))
- {
- int index = result - 1;
- int arrayLength = arrayFullNames.Length;
- if (index >= 0 && arrayFullNames.Length > index)
- {
- arrayFullNames = DecreaseArray(arrayFullNames, index);
- arrayPositions = DecreaseArray(arrayPositions, index);
- return;
- }
- }
- Console.WriteLine("Неверный индекc");
- }
- private static string[] DecreaseArray(string[] array, int index)
- {
- string[] tempArray = new string[array.Length - 1];
- for (int i = 0; i < index; i++)
- {
- tempArray[i] = array[i];
- }
- for (int i = index; i < tempArray.Length; i++)
- {
- tempArray[i] = array[i + 1];
- }
- return tempArray;
- }
- private static void ShowAllDossier(string[] arrayFIO, string[] arrayPost)
- {
- int index = 1;
- for (int i = 0; i < arrayFIO.Length; i++)
- {
- Console.WriteLine($"{index}) {arrayFIO[i]} - {arrayPost[i]}");
- index++;
- }
- }
- private static void SearchDossier(string[] arrayFIO, string[] arrayPost)
- {
- Console.WriteLine("Введите фамилию");
- string lastName = Console.ReadLine();
- int index = 1;
- for (int i = 0; i < arrayFIO.Length; i++)
- {
- var split = arrayFIO[i].Split(" ");
- if (split[0].ToLower() == lastName.ToLower())
- {
- Console.WriteLine($"{index}) {arrayFIO[i]} - {arrayPost[i]}");
- return;
- }
- index++;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement